usort
PHP 4, PHP 5, PHP 7, PHP 8
usort - Sort an array by values using a user-defined comparison function
Example #1 usort example
Result: 0: 1
1: 2
2: 3
3: 5
4: 6
Example #2 usort example using multi-dimensional array
Result: $fruits[0]: apples
$fruits[1]: grapes
$fruits[2]: lemons
Example #3 usort example using a closure
to sort a multi-dimensional array
Result: y, a
x, b
z, c
Example #4 usort example using the spaceship operator
Result: Baldwin, Adam
Baldwin, Alec
West, Adam
Example #5 usort example using a member function of an object
Result: b
c
d