PHP Array uksort() Function
Last Updated : 17 Mar 2025
The PHP uksort( ) function is used to sort an array by the elements keys 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 uksort( ) function returns true on success or false on failure.
Example 1
Output:
Array
(
[d] => mango
[b] => banana
[a] => apple )
Example 2
Output:
Array
(
[6] => python
[4] => ruby
[2] => php
[1] => java
)
Example 3
Output:
Array
(
[a] => 9
[b] => 2
[c] => 60
[d] => 78
)
Example 4
Output:
Array
(
[8] => football
[4] => badminton
[2] => hockey
[1] => cricket
)
Next TopicPhp-array-unique-function