usort

PHP 4, PHP 5, PHP 7, PHP 8
usort - Sort an array by values using a user-defined comparison function
Manual
Code Examples

Example #1 usort example

Result: 0: 1 1: 2 2: 3 3: 5 4: 6
PHP Version:

Example #2 usort example using multi-dimensional array

Result: $fruits[0]: apples $fruits[1]: grapes $fruits[2]: lemons
PHP Version:

Example #3 usort example using a closure to sort a multi-dimensional array

Result: y, a x, b z, c
PHP Version:

Example #4 usort example using the spaceship operator

Result: Baldwin, Adam Baldwin, Alec West, Adam
PHP Version:

Example #5 usort example using a member function of an object

Result: b c d
PHP Version: