PHP » GoLang |
login |
register |
about
|
usort(PHP 4, PHP 5, PHP 7) usort — Sort an array by values using a user-defined comparison function DescriptionThis 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 See Also
|
more
Recently updated
more
Most requested
more
Last requests
|