PHP has some functions for sorting arrays, and this document lists them.
The main differences are:
- Some functions are sorted based on the keys of the array, while others are sorted based on values:$array [' key '] = ' value ';.
- Whether the association between the key and the value can be persisted after sorting means that the key of the array after sorting may be reset to digital type (0,1,2 ... )。
- The order of sorting is: alphabetical order, from low to High (ascending), from high to low (descending), numeric sort, natural sort, random order or user-defined sort.
- Note: All of the following sorting functions are directly acting on the array itself, rather than returning a new ordered array.
- The following functions are not defined in the order in which they are sorted, for elements that are equal in the array. (That is, the order between the equal elements is not stable).
Sort function Properties
Function Name |
sort on |
array index key hold |
Order of sorts |
related Functions |
Array_multisort () |
Value |
Retention of key-value associations, non-retention of numeric types |
The first array is either specified by an option |
Array_walk () |
Asort () |
Value |
Is |
From low to high |
Arsort () |
Arsort () |
Value |
Is |
From high to Low |
Asort () |
Krsort () |
Key |
Is |
From high to Low |
Ksort () |
Ksort () |
Key |
Is |
From low to high |
Asort () |
Natcasesort () |
Value |
Is |
Natural sort, case insensitive |
Natsort () |
Natsort () |
Value |
Is |
Natural sort |
Natcasesort () |
Rsort () |
Value |
Whether |
From high to Low |
Sort () |
Shuffle () |
Value |
Whether |
Random |
Array_rand () |
Sort () |
Value |
Whether |
From high to Low |
Rsort () |
Uasort () |
Value |
Is |
Defined by user |
Uksort () |
Uksort () |
Key |
Is |
Defined by user |
Uasort () |
Usort () |
Value |
Whether |
Defined by user |
Uasort () |
http://php.net/manual/zh/array.sorting.php
Sorting an array