I would like to access each [price] in [prices] in the following array, to output a list and also show the lowest number.
I have tried a foreach loop and the min function but seem to be struggling to access the correct place in the array.
Here is the array (as a variable $prices)
Array (
[0] => Array (
[_id] => 20
[heading] => All Prices
[prices] => Array (
[0] => Array (
[price] => 4.99
)
[1] => Array (
[price] => 9.50
)
[2] => Array (
[price] => .99
)
[3] => Array (
[price] => 6.75
)
[4] => Array (
[price] => 12.97
)
)
[_page] => /region-tests/index.php
[_pageID] => 15
[_sortvalue] => 1000
)
)
foreach ($prices['price'] as $price) {
echo "<li>" . $price . "</li>";
}
echo "The lowest price is: " . min($result[0]['prices']);
But my php above is not outputting a list of prices or the lowest price.
I get the following errors:
For the foreach line:
Notice: Undefined index: price
Warning: Invalid argument supplied for foreach()
And the min line:
Notice: Array to string conversion