PHP二维数组根据键排序
PHP二维数组排序,示例代码
/**
* 二维数组排序
* @param $arr
* @param $keys
* @param string $type
* @return array
*/
function array_sort($arr, $keys, $type = 'desc')
{
$key_value = $new_array = array();
foreach ($arr as $k => $v) {
$key_value[$k] = $v[$keys];
}
if ($type == 'asc') {
asort($key_value);
} else {
arsort($key_value);
}
reset($key_value);
foreach ($key_value as $k => $v) {
$new_array[$k] = $arr[$k];
}
return $new_array;
}