dpf5207 2013-07-25 13:10
浏览 40
已采纳

将关联数组与日期排序为日期顺序

So I have an associative array that's 1 level deep (excerpt as below) but there are a lot of entries

[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
            )

I need a way of looping through this array and re-ordering it so the newest is first and so on. Basically as if you had selected it from a DB and used "ORDER BY "Issued Date" DESC"

I can't really think of a way of doing this.

  • 写回答

2条回答 默认 最新

  • dppxp79175 2013-07-25 13:16
    关注

    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;
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题