I have a number of groups
[ ["id"=>3], ["id"=>1], ["id"=>2]]
Now you want to sort by the ascending ID.
[ ["id"=>1], ["id"=>2], ["id"=>3]]
What should I do? It is best to borrow built-in functions.
Reply content:
I have a number of groups
[ ["id"=>3], ["id"=>1], ["id"=>2]]
Now you want to sort by the ascending ID.
[ ["id"=>1], ["id"=>2], ["id"=>3]]
What should I do? It is best to borrow built-in functions.
http://php.net/manual/en/function.usort.php
usort($arr, 'cmp');function cmp($a, $b){ if ($a['id'] == $b['id']) { return 0; } return ($a['id'] < $b['id']) ? -1 : 1;}
If we can make sure that value is int type,
usort($arr, 'cmp');function cmp($a, $b){ return $a['id'] - $b['id'];}
$data=当前数组;foreach($data as $d){ $arr[$data['id']]=$d;}print_r($arr);
Look, write a function, general, http://blog.csdn.net/igo9go_zq/article/details/48138405.