//根据字段(键名)对二维数组$data进行降序排列
function mult_array_sort($data, $key, $sort = 'ASC')
{
$k = array_column($data, $key);
if (strtoupper($sort) == 'ASC') {
array_multisort($k, SORT_ASC, $data);
} else {
array_multisort($k, SORT_DESC, $data);
}
return $data;
}
另,两个字段排序:
$arr = [ ["f" => 1, "s" => 2], ["f" => 1, "s" => 3], ["f" => 2, "s" => 3], ];
$first = array_column($arr, "f"); $second = array_column($arr, "s");
array_multisort($first, SORT_ASC, $second, SORT_DESC, $arr);
var_dump($arr);