按日期顺序排列日期为的关联数组


Sortind associative array with date to be in date order

所以我有一个1级深的关联数组(摘录如下),但有很多条目

[0] => Array
            (
                [Electronic] => 1
                [Scope] => Intruder Alarm Systems                                                                              
                [Issued Date] => 2013-07-23 01:03:41
                [Customer Name] => qqqq
                [Certificate Number] => 1291087
            )
        [1] => Array
            (
                [Electronic] => 1
                [Scope] => CCTV Systems                                                                                        
                [Issued Date] => 2013-07-23 01:02:01
                [Customer Name] => qqqqq
                [Certificate Number] => 1291085
            )
        [2] => Array
            (
                [Electronic] => 1
                [Scope] => CCTV Systems                                                                                        
                [Issued Date] => 2013-07-17 07:15:06
                [Customer Name] => Accent Foundation Ltd
                [Certificate Number] => 1290822
            )

我需要一种方法来循环这个数组,并重新排序,使最新的是第一个,依此类推。基本上,就好像你从数据库中选择了它,并使用了"ORDER BY"Issued Date"DESC"

我真的想不出办法来做这件事。

您可以使用usort和自己的自定义函数进行排序。

usort($array, function ($a, $b) {
     $atime = strtotime($a['Issue Date']);
     $btime = strtotime($b['Issue Date']);
     return $atime - $btime;
});

在从数据库本身获取数据时始终进行排序/排序,因为循环结构(您想要的方式)在性能方面会很昂贵,因为您已经在从数据库中读取数据,而数据库本身则以最佳方式进行排序。