There are 4 fields in the database, namely Id,volume,edition,name. Requires that the query results be sorted from large to small in volume+edition.
Here's a look at the Array_multisort function
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.
Sort order Flags:
Sort_asc C sorted by ascending order
Sort_desc C sorted in descending order
Sort Type flag:
Sort_regular C Compare Projects by usual method
Sort_numeric C to compare items by numerical value
Sort_string C to compare items by string
You cannot specify two of the same sort flags after each array. Each array after the specified sort flag is valid only for that array, C before this is the default value of SORT_ASC and Sort_regular.
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.
The parameter structure of this function is somewhat unusual, but very flexible. The first argument must be an array. Each of the following parameters can be an array or a sort flag listed below.
So we now have such a set of data
Copy the code code as follows:
This is a set of results from a database query
$data [] = Array (' volume ' = +, ' edition ' = 2);
$data [] = Array (' volume ' = +, ' edition ' = 1);
$data [] = Array (' volume ' = =, ' edition ' = 6);
$data [] = Array (' volume ' = = 98, ' edition ' = 2);
$data [] = Array (' volume ' = +, ' edition ' = 6);
$data [] = Array (' volume ' = +, ' edition ' = 7);
We need to first make an array of volume+edition to
foreach ($data as $val) {
$arr [] = $val [' volume '] + $val [' Edition '];
}
Arrange $arr according to descending order
The $data as the last parameter, sorted by the Universal key
Array_multisort ($arr, Sort_desc, $data);
How to use PHP array_multisort functions to sort a database