usort
Sorts an array by values using a user-defined comparison function, losing original keys.
Parameters
main.php
Return Values
bool
Returns true on success or false on failure
On success:true and array is sorted in place
On failure:false if comparison function is invalid
Notes
- Modifies the original array by reference
- Comparison function should return -1, 0, or 1
- Reindexes the array with numeric keys starting from 0
- Use uasort() to preserve keys during sorting
Changelog
- 8.0.0: callback parameter is now mandatory
Related Functions
array_diff
ArrayCompares two or more arrays and returns the values from the first array that are not present in any of the other arrays.
comparedifferencefilter
max
MathReturns the highest value among the given values, or the highest value in an array.
maximumcomparehighest
min
MathReturns the lowest value among the given values, or the lowest value in an array.
minimumcomparelowest