PHP usort() Function

PHP usort Function


Definition :

In this tutorial we learned about usort() function

The usort() function is used sorts an array by values using a user-defined comparison function.

Syntax

The basic syntax of the usort() function is given with:

      usort(arraycompare_function);

Parameters

The usort() function accepts the following parameters.

Parameter Description
array Required. Specifies the array to be sorted.
compare_function Optional. Specifies the compare function to use for sorting.

Let's understand with given below example

sort the elements of the $arr array using a user-defined comparison function

Output :

15
17
18
19