PHP 小方法之 二维数组排序

if (! function_exists ( 'multi_array_sort' )) {
function multi_array_sort($arr, $keys, $type = 'desc') {
$keysvalue = $new_array = array ();
foreach ( $arr as $k => $v ) {
$keysvalue [$k] = $v [$keys];
}
if ($type == 'asc') {
asort ( $keysvalue );
} else {
arsort ( $keysvalue );
}
reset ( $keysvalue );
foreach ( $keysvalue as $k => $v ) {
$new_array [] = $arr [$k];
}
return $new_array;
}
}
上一篇:django----常用功能


下一篇:洛谷 P1908 逆序对