PHP has several functions that deal with sorting arrays, and this document exists to help sort it all out.
The main differences are:
$array['key'] = 'value';
| Function name | Sorts by | Maintains key association | Order of sort | Related functions |
|---|---|---|---|---|
| array_multisort() | value | string keys yes, int keys no | first array or sort options | array_walk() |
| asort() | value | yes | ascending | arsort() |
| arsort() | value | yes | descending | asort() |
| krsort() | key | yes | descending | ksort() |
| ksort() | key | yes | ascending | krsort() |
| natcasesort() | value | yes | natural, case insensitive | natsort() |
| natsort() | value | yes | natural | natcasesort() |
| rsort() | value | no | descending | sort() |
| shuffle() | value | no | random | array_rand() |
| sort() | value | no | ascending | rsort() |
| uasort() | value | yes | user defined | uksort() |
| uksort() | key | yes | user defined | uasort() |
| usort() | value | no | user defined | uasort() |