Definition :
In this tutorial we learn about uksort()
function.
The uksort()
function is used to sorts an array by keys using a user-defined comparison function.
The keys are preserved, i.e. the key-to-value mapping will remain unchanged by the sort operation.
The basic syntax of the uksort()
function is given with:
uksort(array, compare_function);
The uksort()
function accepts the following parameters.
Parameter | Description |
---|---|
array | Required. Specifies the array to be sorted. |
compare_function | Optional. Specifies the compare function to use for sorting. |
Lets understand with example given below :
Sort the elements of the $arr array by keys using a user-defined comparison function:
Output :
Key=a, Value=17
Key=b, Value=18
Key=c, Value=15
Key=d, Value=19