Get highest value in multi multidimensional array

Viewed 2836

i need to get the the max or highest value in a multi dimensional array.

here is my array $array:

[pay] => Array
(
    [0] => Array
        (
            [title] => Array
                (
                    [name] => 'hi'
                )
            [payment] => Array
                (
                    [amount] => 35
                    [currency] => USD
                )
        )

    [1] => Array
        (
            [title] => Array
                (
                    [name] => 'lol'
                )
            [payment] => Array
                (
                    [amount] => 50
                    [currency] => USD
                )
        )

    [2] => Array
        (
            [title] => Array
                (
                    [name] => 'ok'
                )
            [payment] => Array
                (
                    [amount] => 30
                    [currency] => USD
                )
        )
)

i need to get the max value for amount which is 50. how can i do that?

here is what i tried but it did not work:

$max = -9999999; //will hold max val
$found_item = null; //will hold item with max val;

foreach($array as $k=>$v)
{
    if($v['Total']>$max)
    {
        $max = $v['Total'];
        $found_item = $v;
    }
}
6 Answers
Related