Let's start with the requirements: 4 of the fields in the database are 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– Sort by ascending order
sort_desc– Sorted in descending order
Sort Type flag:
sort_regular– Compare projects by usual method
sort_numeric– the project by numerical comparison
sort_string– to compare items by string
You cannot specify two of the same sort flags after each array. The sort flags specified after each array are valid only for that array-the default values SORT_ASC and Sort_regular before.
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
This is a set of results that are queried from the database $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 make a volume+editio first n Array to foreach ($data as $val) { $arr [] = $val [' volume '] + $val [' Edition '];} The $arr is sorted by descending order//$data as the last parameter, Array_multisort ($arr, Sort_desc, $data) with the Universal key;
That's what we need.