Sort Multi Array in PHP

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

    Use the uasort function, which is user customizable sorting. Like this:

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

提交回复
热议问题