English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The uksort() function sorts the keys in the array using a user-defined comparison function
uksort ( $array, $cmp_function )
The uksort() function sorts the array by element key using a user-defined comparison function.
Serial Number | Parameters and Description |
---|---|
1 | array(Required) It specifies an array. |
2 | cmp_function(Required) If the function is defined, it is used to compare the values and sort them. The function must return-1、0 or1,this method can work normally. It should be written to accept two parameters for comparison, and its working method should be similar to the following−
|
Returns TRUE on success, FALSE on failure.
<?php function cmp_function($a, $b) { if ($a == $b) return 0; return ($a > $b) ? -1 : 1; } $input = array("d"=>"lemon", "a"=>"orange", "b"=>"banana" ); uksort($input, "cmp_function"); print_r($input); ?>Test and see‹/›
Output Result:
Array ( [d] => lemon [b] => banana [a] => orange )