PHP itself is a function that has a multidimensional array ordering.
BOOL Array_multisort (array $ar 1 [, Mixed $arg [, mixed $ ... [, Array $ ...]] )
The following is a description of the Array_multisort function in the manual:
Array_multisort () can be used to sort multiple arrays at once, or to sort multidimensional arrays based on one dimension or multidimensional.
The association (string) key name remains the same, but the numeric key name is re-indexed.
The input array is treated as a column of a table and sorted in rows-this is similar to the function of the SQL ORDER by clause. The first array is the primary array to sort. The rows (values) in the array are compared to the same words, sorted by the size of the corresponding values in the next input array, and so on.
As you can see from the manual, the multidimensional ordering of PHP itself is sorted by the first array, and the subsequent order is adjusted. Arrays like this:
Array (' id ' = = Array (1,3,2),
' Data ' =>array (' A ', ' C ', ' B '))
As long as the ID of the multidimensional sort, you can. But most of the time, the array we construct is this:
Array
Array (' ID ' =>1, ' data ' = ' a '),
Array (' ID ' =>3, ' data ' = ' C '),
Array (' ID ' =>2, ' data ' = ' B ')
);
The elements of the array are arranged in rows and need to be sorted by one of the columns. PHP does not seem to provide a function like a matrix transpose, so it is not possible to use Array_multisort directly for multidimensional sorting. However, you just need to extract the sorted columns first, and pass them as the first parameter to Array_multisort.
function Multi_array_sort ($multi _array, $sort _key, $sort =sort_asc) { if (Is_array ($multi _array)) { foreach ($ Multi_array as $row _array) { if (Is_array ($row _array)) { $key _array[] = $row _array[$sort _key]; } else{ return-1;}}} else{ return-1; } Array_multisort ($key _array, $sort, $multi _array); return $multi _array; }