...
The sort()
operator takes an optional argument and returns an array that is the original array sorted according to the following criteria:
- If the argument is empty or the string "
default"
, the array will be sorted in ascending order using thecmp
operator. - If the argument is the string "
reverse"
, the array will be sorted in descending order using thecmp
operator. - If the argument is the string "
numeric"
, the array will be sorted in ascending order using the<=>
operator. - If the argument is the string "
ciremun"
("numeric" backwards), the array will be sorted in descending order using the<=>
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.
...