多个数组根据某一列进行排序
array_multisort() 函数返回排序数组。您可以输入一个或多个数组。函数先对第一个数组进行排序,接着是其他数组,如果两个或多个值相同,它将对下一个数组进行排序。array_multisort(array1,sorting order,sorting type,array2,array3...)
字符串键名将被保留,但是数字键名将被重新索引,从 0 开始,并以 1 递增。
/**
* 多维数组根据指定列进行排序
*
* @param <type> $arr 等待排序的数组
* @param <type> $field 指定列
* @param string $order 排序方向
*
* @return <type> 排序后的数组
*/
function arr_multisort($arr, $field, $order="desc"){
if($order="desc"){
$direction = "SORT_DESC";
}else{
$direction = "SORT_ASC";
}
$sort = array(
'direction' => $direction,
'field' => $field
);
foreach ($arr as $key => $value) {
foreach ($value as $k => $v) {
$arrSort[$k][$key] = $v;
}
}
if($sort['direction']){
array_multisort($arrSort[$sort['field']], constant($sort['direction']), $arr);
}
return $arr;
}