Sorting an array with DateTime strings?

后端 未结 6 1349
深忆病人
深忆病人 2021-01-20 03:57

How can i sort efficiently this array (recent items first) on end_time value in PHP?

array
  0 => 
    array
      \'value\' => int 4
             


        
6条回答
  •  囚心锁ツ
    2021-01-20 04:46

    Try:

    
    function sort_datewise($x, $y) {
        $t1 = strtotime($x['end_time']);
        $t2 = strtotime($y['end_time']);
        return $t1 - $t2;
    }    
    usort($array, 'sort_datewise');
    
    

提交回复
热议问题