PHP Array uasort() Function
Last Updated : 17 Mar 2025
The PHP uasort( ) function is used to sort an array by its values using a user-defined comparison function. This function was introduced in PHP 4.0.
Syntax
Parameter
| Parameter | Description | Is compulsory |
|---|---|---|
| array | Specifies the array to be sorted. | compulsory |
| user_defined_function | This function is a comparison function and it is used to compare values and sort the array. This function returns three types of values.
| Optional |
Return type
The uasort( ) function returns true on success or false on failure.
Example 1
Output:
Array
(
[b] => badminton
[d] => cricket
[c] => football
[a] => tennis
)
Example 2
Output:
Array
(
[2] => tata
[4] => ford
[1] => datsun
[5] => audi
)
Example 3
Output:
Array
(
[d] => coconut
[b] => banana
[a] => apple
)
Example 4
Output:
Array
(
[f] => 4
[b] => 3
[a] => 2
[d] => 1
)
Next Topic