usort

bool usort(array array, string func) 
array Array to sort using the supplied function
func Function to use to sort the array

Sorts the given scalar array with a user-defined function.

Returns:

TRUE on success; FALSE on error

Description:

usort() sorts array according to the user-defined function named by func . This can be useful for doing sorts with custom algorithms or doing non-case-sensitive sorts with alphabetic characters. When you pass usort() an array and the name of a user-defined function, it uses the bubblesort method and traverses the elements of the array to sort them. The custom function must return -1, 0, or 1 for this method to work correctly (see example). If used on an associative array, this function causes the keys ...

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.