PHP: Sorting a associative multidimensional array -


i have associate multidimensional array here trying make names print in ascending order, date printing in ascending order. new php , not sure how make happen. read use array_multisort function i'm not sure if have done right. can me out or tell me going wrong?

$win = [      'jane doe' => '7 october 2015'."<br/>",      'nash patel' => '14 october 2014'."<br/>",      'joe public' => '12 october 2016'."<br/>"          ];         foreach($win $key => $ent) {       echo '<strong>' . $key . '</strong> - ' . $ent . php_eol;       }      foreach($win $c=>$key) {             $sort_date[] = $key['date'];             $sort_name[] = $key['name'];         }          array_multisort(sort_asc, sort_asc, $win);         print_r($win); 

this works me:

<?php  $arr = array(     'jane doe'   => '7 october 2015'."<br/>",      'nash patel' => '14 october 2014'."<br/>",      'joe public' => '12 october 2016'."<br/>"  );  foreach( $arr $k => $v ) {     $names[] = $k;      $d = str_replace('<br/>','',$v);     $dates[] = datetime::createfromformat('j f y', $d ); }  sort( $names ); sort( $dates );  echo '<pre>'; print_r( $names ); echo '</pre>';  echo '<pre>'; foreach( $dates $date ) {     $formatted_dates[] = $date->format('j f y'); } print_r( $formatted_dates ); echo '</pre>'; 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -