PHP has a rich library of predefined functions, and that also includes different sorting functions. It has different functions to sort a list of items in an array either by value or by key/index. We can also keep the association of the array's values with their respective keys while doing the sorting. Another important function of PHP is the built-in function for sorting a multi-dimensional array. Here is a summary of these functions:
Function name |
Purpose |
sort() |
This sorts an array in ascending order. Value/key association is not preserved. |
rsort() |
Sort an array in reverse/descending order. Index/key association is not preserved. |
asort() |
Sort an array while maintaining index association. |
arsort() |
Sort an array in reverse order and maintain index association. |
ksort() |
Sort an array by key. It maintains... |