This article introduces an example of using the array_multisort function to sort two-dimensional arrays in PHP. Friends in need can refer to it. Following the previous article: PHP two-dimensional array sorting custom function, today, we introduce another example of PHP two-dimensional array sorting.
PHP sorting a two-dimensional array is very simple, mainly using the array_multisort function.
Example:
Copy code The code is as follows:
/**
* php two-dimensional array sorting
* edit www.jb51.net
*/
$data = array();
$data[] = array('volume' => 67, 'edition' => 2);
$data[] = array(' volume' => 86, 'edition' => 1);
$data[] = array('volume' => 85, 'edition' => 6);
$data[] = array('volume' => 98, 'edition' => 2);
$data[] = array('volume' => 86, 'edition' => 6);
$data[] = array('volume' => 67, 'edition' => 7);
// Get the 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 result:
Copy code The code is as follows:
Array
(
[0] = > Array
(
[1] => Array
( )
[2] => Array
( )
[3] => Array
( )
[4] => Array
( )
[5] => Array
( )
)
Note:
The parameters of the array_multisort function are very flexible. You can refer to the instructions in the PHP manual for in-depth study.
http://www.bkjia.com/PHPjc/621678.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/621678.htmlTechArticleThis article introduces an example of using the array_multisort function to sort two-dimensional arrays in PHP. Friends in need, please refer to the following Bar. Following the previous article: PHP two-dimensional array sorting custom function,...