Array_multisort-sorts multiple arrays or multi-dimensional arrays.

Source: Internet
Author: User
: This article mainly introduces array_multisort-sorting multiple arrays or multi-dimensional arrays. For more information about PHP tutorials, see. Array_multisort-if multiple arrays or multi-dimensional arrays are sorted successfully, true is returned. otherwise, false is returned.

The input array is treated as a table column and sorted BY rows. This is similar to the SQL ORDER BY clause. The first array is the main array to be sorted. If the rows (values) in the array are the same, they are sorted according to the size of the corresponding values in the next input array, and so on .?
The first parameter must be an array. Each of the following parameters can be an array or a sorting flag listed below.

Sort order mark:

? SORT_ASC-sort by ascending order

? SORT_DESC-sort by descent

? Sorting type flag:

SORT_REGULAR-compare projects by common methods

? SORT_NUMERIC-compare projects by numerical values

? SORT_STRING-compare items by string

Both SORT_STRING and SORT_REGULAR are case-sensitive letters. uppercase letters are placed before lowercase letters. ?

? You cannot specify two Sorting flags of the same type after each array. The sorting flag specified after each array is only valid for this array-the default values are SORT_ASC and SORT_REGULAR.

// The string key name will be retained, but the number key will be re-indexed, starting from 0 and increasing at 1.

Do I need to sort two-dimensional arrays in ascending order of name in descending order?

$ ArrData = [['id' => 1, 'name' => 'hahaha'], ['id' => 0, 'name' => 'aaha'], ['id' => 2, 'name' => 'caha'], ['id' => 4, 'name' => 'zaha'], ['id' => 16, 'name' => 'daha'],];/* now has an array containing rows, but array_multisort () an array containing columns is required. use the following code to retrieve columns and sort them. ? */Foreach ($ arrDataas $ key => $ value ){? $ Id [$ key] = $ value ['id']; $ arr [$ key] = $ value ['name'];} // use the sorting array $ arrData as the last parameter? Array_multisort ($ id, SORT_DESC, $ arr, SORT_ASC, $ arrData); print_r ($ arrData );

Reprinted or share please specify the address thank you: http://blog.csdn.net/w19981220

Copyright Statement: Respect yourself for the fruits of others' work. thank you !!

The above introduces array_multisort-sorting multiple arrays or multi-dimensional arrays, including the content, and hope to be helpful to friends who are interested in the PHP Tutorial.

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.