Menu Samaritan's Purse

USORT

Sort an array by values using a user-defined comparison function

SYNTAX

usort ( array &$array , callable $value_compare_func ) : bool

PARAMETERS

array

The input array.

value_compare_func

The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

callback ( mixed $a, mixed $b ) : int

Caution: Returning non-integer values from the comparison function, such as float, will result in an internal cast to integer of the callback's return value. So values such as 0.99 and 0.1 will both be cast to an integer value of 0, which will compare such values as equal.

RETURN

Returns TRUE on success or FALSE on failure.

EXAMPLES

1

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 5
    [4] => 6
)

2

$array[0]: apples
$array[1]: grapes
$array[2]: lemons

3

b
c
d

4

y, a
x, b
z, c

PHP