php 根据二维数组中的某一字段进行排序:
$dataArr = [
'0' = [
'code' => 'hfvdp',
'status' => 0,
],
'1' = [
'code' => 'vhbfgjd',
'status' => 9,
],
'2' = [
'code' => 'cbsdhj',
'status' => 3,
],
]
$timeKey = array_column( $dataArr, 'status'); //取出数组中status的一列,返回一维数组
array_multisort($timeKey, SORT_DESC, $dataArr);//排序,根据$status 排序
注: array_multisort() 不用重新赋值
结果为:
//排序后
$dataArr = [
'0' = [
'code' => 'vhbfgjd',
'status' => 9,
],
'1' = [
'code' => 'cbsdhj',
'status' => 3,
],
'2' = [
'code' => 'hfvdp',
'status' => 0,
],
]