...
- If the argument is empty, the array will be sorted in ascending order using a string comparisonthe
cmp
operator. - If the argument is the string "
reverse"
, the array will be sorted in descending order using a string comparisonthecmp
operator. - If the argument is the string "
numeric"
, the array will be sorted in ascending order using a number comparisonthe<=>
operator. - If the argument is the string "
ciremun"
("numeric" backwards), the array will be sorted in descending order using a number comparisonthe<=>
operator. - If the argument is a function, the function will be used to perform pair-wise comparisons of the members of the array for purposes of doing the sort. The function must take two arguments and return -1, 0, or 1 depending on whether the first argument is less than, equal to, or greater than the second. The
<=>
andcmp
comparison operators are useful with sort().
Note that because the default behavior is to do a string comparison, number sorts can give unexpected results, as shown in the first example.
...