A simple example of sorting a two-dimensional array in PHP_PHP tutorial

WBOY
Release: 2016-07-13 17:18:14
Original
809 people have browsed it

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.

www.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,...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!