Array sorting by value

I have the following array;

Array
(
[0] => Array
(
[value] => 10
[base] => 2.99
[renewal] => 1.99
)

[1] => Array
    (
        [value] => 50
        [base] => 3.99
        [renewal] => 2.99
    )

[2] => Array
    (
        [value] => 100
        [base] => 4.99
        [renewal] => 3.99
    )

)

But need to sort according to the value entry “highest first”. I’m currently using array_reverse but the input order is not necessarily going to be lowest to highest so I need a more reliable method.

Could somebody please point me in the right direction?

Thanks in advance.

Have a read about the [FONT=courier new]array_multisort()[/FONT] function which may be what you want to use.

This might help you:

$array[0] = array('value' => 10, 'base' => 2.99, 'renewal' => 1.99);
$array[1] = array('value' => 50, 'base' => 3.99, 'renewal' => 2.99);
$array[2] = array('value' => 100, 'base' => 4.99, 'renewal' => 3.99);

function cmp($a, $b){
    if ($a == $b)
        return 0;
    
    return $a['value'] < $b['value'];
}

usort($array, 'cmp');

echo '<pre>';
print_r($array);
echo '</pre>';

Result is:

Array
(
[0] => Array
(
[value] => 100
[base] => 4.99
[renewal] => 3.99
)

[1] =&gt; Array
    (
        [value] =&gt; 50
        [base] =&gt; 3.99
        [renewal] =&gt; 2.99
    )

[2] =&gt; Array
    (
        [value] =&gt; 10
        [base] =&gt; 2.99
        [renewal] =&gt; 1.99
    )

)

Thanks folks. array_multisort was exactly what I was looking for.