sort array based on the dateTime in php

后端 未结 6 1442
予麋鹿
予麋鹿 2020-12-05 13:37
Array
        (
            [0] => Array
                (
                    [dateTime] => 2011-10-18 0:0:00
                    [chanl1] => 20.7
                 


        
6条回答
  •  一生所求
    2020-12-05 14:29

    Simple sorting for DateTime objects with the spaceship operator:

    $list = [
        new DateTime('yesterday'),
        new DateTime('today'),
        new DateTime('1 week ago'),
    ];
    
    uasort($list, function ($a, $b) {
        return $a <=> $b;
    });
    
    var_dump($list);
    

提交回复
热议问题