php 二维数组根据特定字段排序

$arr = array(
    array(
        'id' => 5,
        'time'  => '2018-01-05',
     'order' => 1 ), array( 'id' => 3, 'time' => '2018-01-03',
     'order' => 2 ), array( 'id' => 1, 'time' => '2018-01-01',
     'order' => 1 ), array( 'id' => 2, 'time' => '2018-01-02',
     'order' => 3 ), array( 'id' => 4, 'time' => '2018-01-04',
     'order' => 2 ) ); $sortField = array_column($arr, 'time'); //time 要排序的字段
array_multisort($sortField, SORT_DESC, $arr);
//array_multisort(array_column($arr, 'order'), SORT_DESC, array_column($arr, 'id'), SORT_ASC, $exchangeList); 多个字段同时排序

 

posted @ 2019-11-06 09:39  pengcx  阅读(163)  评论(0编辑  收藏  举报