Sort Multi Array in PHP

后端 未结 9 1914
清酒与你
清酒与你 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:04

    What you want is UASORT.

    http://us3.php.net/manual/en/function.uasort.php

    function would be like:

    function cmp($a, $b) {
        $d1 = strtotime($a['date']);
        $d2 = strtotime($b['date']);
        if ($d1 == $d2) {
           return 0;
        }
        return ($d1 < $d2) ? -1 : 1;
    }
    

提交回复
热议问题