|
usortSort an array by values using a user-defined comparison function Description
bool usort
( array
&$array
, callable $value_compare_func
)This function will sort an array by its values using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function.
Parameters
Return Values
Returns Examples
Example #1 usort example
<?php The above example will output: 0: 1 1: 2 2: 3 3: 5 4: 6
Example #2 usort example using multi-dimensional array
<?php When sorting a multi-dimensional array, $a and $b contain references to the first index of the array. The above example will output: $fruits[0]: apples $fruits[1]: grapes $fruits[2]: lemons
Example #3 usort example using a member function of an object
<?php The above example will output: b c d Example #4 usort example using a closure to sort a multi-dimensional array
<?php The above example will output: y, a x, b z, c |