A simple PHP two-dimensional array is sorted by the elements in the second dimension so that it does not affect the data, only the contents of the array to sort, the need for a friend reference.
| The code is as follows |
Copy Code |
$ar = Array (
0 = = Array (' A ' =>5, ' B ' =>3, ' C ' =>3),
1 = = Array (' A ' =>5, ' B ' =>2, ' C ' =>1),
2 = = Array (' A ' =>1, ' B ' =>1, ' C ' =>2)
);
$a = array ();
$b = Array ();
foreach ($ar as $k = = $v) {
$a [$k] = $v [' a '];
$b [$k] = $v [' B '];
$c [$k] = $v [' C '];
}
Array_multisort ($a, SORT_ASC, $ar);
Array_multisort ($a, Sort_desc, $b, SORT_ASC, $ar);
Print_r ($ar); |
http://www.bkjia.com/PHPjc/631681.html www.bkjia.com true http://www.bkjia.com/PHPjc/631681.html techarticle a simple PHP two-dimensional array is sorted by the elements in the second dimension so that it does not affect the data, only the contents of the array to sort, the need for a friend reference. Code ...