I have the follow xml that I took from this link
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>
</breakfast_menu>
I would like to know the php array that could generate the above xml.
If I do this:
$arrTest1=[
"breakfast_menu"=>[
"food"=>[
"name"=>"Belgian Waffles",
"price"=>"$5.95",
"description"=>"Our famous Belgian Waffles with plenty of real maple syrup",
"calories"=>650
],
"food"=>[
"name"=>"French Toast",
"price"=>"$4.50",
"description"=>"Thick slices made from our homemade sourdough bread",
"calories"=>600
],
"food"=>[
"name"=>"Homestyle Breakfast",
"price"=>"$6.95",
"description"=>"Two eggs, bacon or sausage, toast, and our ever-popular hash browns",
"calories"=>950
]
]
];
I will have only the last food node (same index string).
If I do this:
$arrTest2=[
"breakfast_menu"=>[
"food"=>[
[
"name"=>"Belgian Waffles",
"price"=>"$5.95",
"description"=>"Our famous Belgian Waffles with plenty of real maple syrup",
"calories"=>650
],
[
"name"=>"French Toast",
"price"=>"$4.50",
"description"=>"Thick slices made from our homemade sourdough bread",
"calories"=>600
],
[
"name"=>"Homestyle Breakfast",
"price"=>"$6.95",
"description"=>"Two eggs, bacon or sausage, toast, and our ever-popular hash browns",
"calories"=>950
]
]
]
];
I will not have the <food/>
node in my xml document, using SimpleXMLElement. Instead, I will have the node <element0/>
, <element1/>
, ... .
So what should be the best array design that could generate back the xml?