-1

所以我有一个深度为 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"

我真的想不出这样做的方法。

4

2 回答 2

1

You can use usort with your own custom function to sort.

usort($array, function ($a, $b) {
     $atime = strtotime($a['Issue Date']);
     $btime = strtotime($b['Issue Date']);
     return $atime - $btime;
});
于 2013-07-25T13:16:36.293 回答
0

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

于 2013-07-25T13:18:34.503 回答