: 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.