Hello Bonesnap,
Thanks for your prompt reply.
Yes, I have read json_decod on php.net et al, but must confess to being little the wiser.
Below is the formatted result of Print_r($data) and beneath that the the output from a var_dump.
Array (
[courses] => Array (
[starters] => Array (
[0] => Array (
[meal] => Nachos to share enough for two
[notes] => Lightly salted tortilla chips, melted mozzarella and jalopenos with salsa, sour cream and guacamole
[price] => 5.95
)
)
[mains] => Array (
[0] => Array (
[meal] => Beer Battered Cod Large or small
[notes] => With mushy peas and our own spicy pickled onion, Tartar sauce and chips
[price] => 12.95
)
)
)
)
array(1) { ["courses"]=> array(2) { ["starters"]=> array(1) { [0]=> array(3) { ["meal"]=> string(30) "Nachos to share enough for two" ["notes"]=> string(99)
"Lightly salted tortilla chips, melted mozzarella and jalopenos with salsa,
sour cream and guacamole" ["price"]=> string(4) "5.95" } } ["mains"]=> array(1) { [0]=> array(3) { ["meal"]=> string(32) "Beer Battered Cod Large or small" ["notes"]=> string(71) "With mushy peas and our own spicy pickled onion, Tartar sauce and chips" ["price"]=> string(5) "12.95" } } } }
The following is essentially the code that I have been playing around with...
<?php
$file = 'menu.json';
$json = file_get_contents($file); //Get the contents of the menu file - menu.json
$data = json_decode($json,true); //decode the data
foreach($data["courses"] as $course){
print("<div class='course' id='".$data["courses"][0]."'>");
print("<div class='mnuTitle'>Starters</div><ul>");
foreach($course as $item){
print("<li><span class='menuMain'>");
print($item["meal"]);
print("</span><span class='menuSmall'>");
print($item["notes"]);
print("</span><span class='menuPrice'>£");
print($item["price"]);
print("</span></li>");
}
print("</ul></div>");
}
?>
Both of the foreach loops work as expected with the exception that it does not pull out the menu "course" i.e. print("<div class='course' id='".$data["courses"][0]."'>"); I am wanting to use this information, the course name, e.g. Starters, Mains, Deserts, etc, as an ID and title, but so far with little success!!