PHP5.5以下: $key_arrays[]='排序字段'; $coupons_list=array('1','2','3');//排序数组 foreach ($coupons_list as $cou) { $key_arrays[]=$cou['to_time']; } //即将结束 array_multisort($key_arrays,SORT_ASC,SORT_NUMERIC,$coupons_list);
PHP5.5以上: $data = [ [ 'id' => 13, 'name' => 'Arthur Dent', ], [ 'id' => 22, 'name' => 'Ford Prefect', ], [ 'id' => 5, 'name' => 'Trillian Astra', ], ]; //对多维数组进行排序,就是这么简单! // array_multisort(array_column($data, 'id'), SORT_ASC, $data); array_multisort(array_column($data, 'id'), SORT_DESC, $data);