This article introduces the use of the Array_multisort function in PHP for two-dimensional array ordering examples, there is a need for friends, refer to the bar. Following an article: Php two-dimensional array sorting custom function, today, we introduce a PHP two-dimensional array ordering example.
PHP is a simple sort of two-dimensional array, mainly used for array_multisort functions.
Example:
Copy Code code as follows:
<?php
/**
* PHP two-dimensional array ordering
* Edit Www.jb51.net
*/
$data = Array ();
$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);
Get a list of columns
foreach ($data as $key => $row)
{
$volume [$key] = $row [' volume '];
$edition [$key] = $row [' Edition '];
}
Array_multisort ($volume, Sort_desc, $edition, SORT_ASC, $data);
Print_r ($data);
?>
Output results:
Copy Code code as follows:
Array
(
[0] => Array
(
[Volume] => 98
[Edition] => 2
)
[1] => Array
(
[Volume] => 86
[Edition] => 1
)
[2] => Array
(
[Volume] => 86
[Edition] => 6
)
[3] => Array
(
[Volume] => 85
[Edition] => 6
)
[4] => Array
(
[Volume] => 67
[Edition] => 2
)
[5] => Array
(
[Volume] => 67
[Edition] => 7
)
)
Description
Array_multisort function parameters are very flexible, you can refer to the instructions in the PHP manual, in-depth study.