PHPcodefunctionarray_sort ($ arr, $ field, $ by = SORT_ASC) {foreach ($ arras $ v) {$ r [] = sharing a simple method for sorting two-dimensional arrays
PHP code
Function array_sort ($ arr, $ field, $ by = SORT_ASC) {foreach ($ arr as $ v) {$ r [] = $ v [$ field];} array_multisort ($ r, $ by, $ arr); return $ arr;} $ array = array ('name' => 'phone ', 'brand' => 'Nokia ', 'price' => 3000), array ('name' => 'laptop', 'brand' => 'Lenovo ', 'price' => 4000),); $ a = array_sort ($ array, 'price', SORT_DESC); echo""; print_r($a);
Welcome...
------ Solution --------------------
This is always the case.
------ Solution --------------------
It is better not to encapsulate the array_multisort directly.
------ Solution --------------------
Php has the function of automatic sorting.
------ Solution --------------------
Do I need to encapsulate another 3D array?
------ Solution --------------------
Discussion
Do I need to encapsulate another 3D array?