The usort function sorts an array by values using a user-defined comparison function.

    
    function comparatorFunc( $x, $y) {
        if ($x== $y)
            return 0;
        if ($x < $y)
            return -1;
        else
            return 1;
    }

    $numbers = array(2, 9, 1, 3, 5);

    usort($numbers, "comparatorFunc");

    print_r($arr);
    // Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 5 [4] => 9 );