I have an array {code...}. now I want to sort the {code...} in ascending order of id. what should I do? It is best to borrow built-in functions. I have an array
[ ["id"=>3], ["id"=>1], ["id"=>2]]
Sort IDs in ascending order.
[ ["id"=>1], ["id"=>2], ["id"=>3]]
What should I do? It is best to borrow built-in functions.
Reply content:
I have an array
[ ["id"=>3], ["id"=>1], ["id"=>2]]
Sort IDs in ascending order.
[ ["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 determine that all values are int type
usort($arr, 'cmp');function cmp($a, $b){ return $a['id'] - $b['id'];}
$ Data = current array; foreach ($ data as $ d) {$ arr [$ data ['id'] = $ d;} print_r ($ arr );
You see, write a function, general, http://blog.csdn.net/igo9go_zq/article/details/48138405