PHP uasort() Function

PHP uasort Function


Definition :

The uasort() function is used to sorts an array by values using a user-defined comparison function.

The keys are preserved, i.e. the key-to-value mapping will remain unchanged by the sort operation.

Syntax

The basic syntax of the uasort() function is given with:

    uasort(arraycompare_function);

Parameters

The uasort() 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 example Sort the elements of the $arr array by values using a user-defined comparison function:

 

Output :

Key=c, Value=15
Key=a, Value=17
Key=b, Value=18
Key=d, Value=19