数组
$data=array(
0=>array('age'=>34,'name'=>'小1'),
1=>array('age'=>45,'name'=>'小2'),
2=>array('age'=>47,'name'=>'小3'),
3=>array('age'=>12,'name'=>'小4'),
4=>array('age'=>15,'name'=>'小5'),
5=>array('age'=>85,'name'=>'小6'),
);
先取出要排序的列
foreach($data as $val){
$arrays[]=$val['age'];
}
使用php函数 array_multisort 进行排序处理 SORT_DESC 倒序 , SORT_ASC顺序
array_multisort($arrays,SORT_ASC,SORT_NUMERIC,$data);
var_dump($data);
排序后的数据
array(6) {
[0] => array(2) {
["age"] => int(12)
["name"] => string(4) "小4"
}
[1] => array(2) {
["age"] => int(15)
["name"] => string(4) "小5"
}
[2] => array(2) {
["age"] => int(34)
["name"] => string(4) "小1"
}
[3] => array(2) {
["age"] => int(45)
["name"] => string(4) "小2"
}
[4] => array(2) {
["age"] => int(47)
["name"] => string(4) "小3"
}
[5] => array(2) {
["age"] => int(85)
["name"] => string(4) "小6"
}
}