Current Location: Home> Function Categories> uksort

uksort

Use user-defined comparison functions to sort key names in an array
Name:uksort
Category:Array
Programming Language:php
One-line Description:Use a user-defined comparison function to sort key names in an array.

Definition and usage

The uksort() function sorts the array key names through user-defined comparison functions.

Tip: Please use the uasort() function to sort the array by key value through a user-defined comparison function, which uses a user-defined comparison function to sort.

Example

Use a user-defined comparison function to sort the key names of elements in the array $arr:

 <?php
function my_sort ( $a , $b )
{
if ( $a == $b ) return 0 ;
return ( $a < $b ) ? - 1 : 1 ;
}

$arr = array ( "a" => 4 , "b" => 2 , "c" => 8 , d => "6" ) ;
uksort ( $arr , "my_sort" ) ;
?>

Try it yourself

Similar Functions
Popular Articles