Arrays
PHP Manual

Sorting Arrays

PHP has several functions that deal with sorting arrays, and this document exists to help sort it all out.

The main differences are:

Sorting function attributes
Function name Sorts by Maintains key association Order of sort Related functions
array_multisort() value associative yes, numeric no first array or sort options array_walk()
asort() value yes low to high arsort()
arsort() value yes high to low asort()
krsort() key yes high to low ksort()
ksort() key yes low to high asort()
natcasesort() value yes natural, case insensitive natsort()
natsort() value yes natural natcasesort()
rsort() value no high to low sort()
shuffle() value no random array_rand()
sort() value no low to high rsort()
uasort() value yes user defined uksort()
uksort() key yes user defined uasort()
usort() value no user defined uasort()


Arrays
PHP Manual