PHP Array Operation Instance Tutorial
Each cell in the data array represents a row in a table. This is the typical way the database holds array data.
The data in the example are as follows:
Volume | Edition
-------+--------
67 | 2
86 | 1
85 | 6
98 | 2
86 | 6
67 | 7
The data is all stored in an array named data. This is usually done by looping through the database, such as MYSQL_FETCH_ASSOC () (In fact, you can think of the same as the MYSQL_FETCH_ASSOC () function, and you can see the difference between the keys in the PHP manual).
$data [] = Array (' volume ' =>, ' Edition ' => 2);
$data [] = Array (' volume ' =>, ' edition ' => 1);
$data [] = Array (' volume ' =>, ' Edition ' => 6);
$data [] = Array (' volume ' =>, ' Edition ' => 2);
$data [] = Array (' volume ' =>, ' Edition ' => 6);
$data [] = Array (' volume ' =>, ' edition ' => 7);
In this example, the volume is sorted in descending order and the edition in ascending order.
Now you have an array with rows, but Array_multisort () needs an array of columns, so use the following code to get the columns, and then sort.
Get a list of columns
foreach ($data as $key => $row) {
$volume [$key] = $row [' volume '];
$edition [$key] = $row [' Edition '];
}
Arranges data in descending order according to volume, sorted by edition ascending order
Sort the $data as the last parameter in a common key
Array_multisort ($volume, Sort_desc, $edition, SORT_ASC, $data);
The data collection is now sorted, and the results are as follows:
Volume | Edition
-------+--------
98 | 2
86 | 1
86 | 6
85 | 6
67 | 2
67 | 7
There are actually a lot of ways to do it in a sort of way, such as the Arsort (), Asort (), Ksort (), Krsort (), Natsort (), Natcasesort (), Rsort () and Usort ( ), Array_multisort () and Uksort ().