A simple example of a _php sequence of two-dimensional arrays in PHP

Source: Internet
Author: User
Tags arrays

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.

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.