I have the following array and I can't figure out how to get any values out of it, this is the array:
Array
(
[0] => stdClass Object
(
[aure] => test
[menu] => stdClass Object
(
[pizza] => stdClass Object
(
[Tomato & Cheese] => stdClass Object
(
[small] => 5.50
[large] => 9.75
)
[onion] => stdClass Object
(
[small] => 5.50
[large] => 9.75
)
)
[Special Dinners] => stdClass Object
(
[Chicken Wings Dinner] => stdClass Object
(
[price] => 15.80
)
[onion] => stdClass Object
(
[small] => 5.50
[large] => 9.75
)
)
)
)
)
would you be able to give me an example of how can I get the price for a small Tomato & cheese pizza?
$array[0]->menu->pizza->{"Tomato & Cheese"}->small;
I have used curly brackets because I'm not able to get "Tomato & Cheese" without them (they have spaces)
This will give you all pizzas
$pizzas = (array) $array[0]->menu->pizza;
foreach($pizzas as $pizzaname => $choices){
echo $pizzaname." (small) is for ".$choices->small."<br />";
echo $pizzaname." (large) is for ".$choices->large."<br />";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With