标签:
1、先直接上函数
function array_sort($arr,$keys,$type=‘asc‘){
$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[$k] = $arr[$k];
}
return $new_array;
}
下面看一个给定的二位数组
$person = array(
array(‘id‘=>1,‘name‘=>‘fj‘,‘weight‘=>100,‘height‘=>180),
array(‘id‘=>2,‘name‘=>‘tom‘,‘weight‘=>53,‘height‘=>150),
array(‘id‘=>3,‘name‘=>‘jerry‘,‘weight‘=>120,‘height‘=>156),
array(‘id‘=>4,‘name‘=>‘bill‘,‘weight‘=>110,‘height‘=>190),
array(‘id‘=>5,‘name‘=>‘linken‘,‘weight‘=>80,‘height‘=>200),
array(‘id‘=>6,‘name‘=>‘madana‘,‘weight‘=>95,‘height‘=>110),
array(‘id‘=>7,‘name‘=>‘jordan‘,‘weight‘=>70,‘height‘=>170)
);
使用方法
$person =array_asort($person,‘weight‘);
标签:
原文地址:http://www.cnblogs.com/zhangkg/p/4717255.html