Php sorts two-dimensional arrays

Source: Internet
Author: User
Php sorts two-dimensional arrays
This article describes how to use the array_multisort function in php to sort two-dimensional arrays. For more information, see.

Following the previous article: PHP two-dimensional array sorting custom function, today we will introduce another example of php two-dimensional array sorting. The sorting of two-dimensional arrays in php is very simple. the array_multisort function is mainly used.

Example:

     67, 'version' => 2); $ data [] = array ('Volume '=> 86, 'version' => 1 ); $ data [] = array ('Volume '=> 85, 'version' => 6); $ data [] = array ('Volume' => 98, 'version' => 2); $ data [] = array ('Volume '=> 86, 'version' => 6 ); $ data [] = array ('Volume '=> 67, 'version' => 7); // get the column list foreach ($ data as $ key => $ row) {$ volume [$ key] = $ row ['Volume ']; $ edition [$ key] = $ row ['version'];} array_multisort ($ volume , SORT_DESC, $ edition, SORT_ASC, $ data); print_r ($ data);?>

Output result:

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 ))

Note: the parameters of the array_multisort function are very flexible. you can refer to the instructions in the php Manual for in-depth research.

>>> For more information, see The php array sorting method <

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.