Sort Multi Array in PHP

后端 未结 9 1911
清酒与你
清酒与你 2021-01-23 07:10

Does anybody have an idea how can I sort this array by key (date) in PHP?

Array
(   
    [2011-02-16] => Array
        (
            [date] => 2011-02-16
          


        
9条回答
  •  情话喂你
    2021-01-23 08:02

    Well, as sorting on the key would do it, ksort() would work for you!

    But if you really want to sort on the date element, you would use uasort() with a sort function like this

      function compare($a, $b)
      {
          if ($a['date']==$b['date']) return 0;
          return ($a['date']>$b['date'])?1:-1;
      }
    
      uasort($myarray, 'compare');
    

提交回复
热议问题