二维数组排序

/*$arr 数组
* $name 排序依据列
* $asc asc正序 desc 倒序
* */
function arr_sort($arr,$name,$type='asc'){
$temp=array();
foreach($arr as $v){
$temp[$v[$name]]=$v;
}
if($type=='asc'){
ksort($temp);
}else{
krsort($temp);
}
return $temp;
}
$attr2=array(
array("id"=>1,"name"=>"liming","age"=>21),
array("id"=>3,"name"=>"daten","age"=>27),
array("id"=>2,"name"=>"xiaohua","age"=>18),
);
echo "<pre>";
var_dump(arr_sort($attr2,"age"));
原文地址:https://www.cnblogs.com/lixiuyuan999/p/6393279.html