Hi all,
I've got a really bad brain block with this.
My XML file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<fruits>
<item>Apple</item>
<item>Orange</item>
<item>Banana</item>
</fruits>
<vegetables>
<item>Lettuce</item>
<item>Carrot</item>
</vegetables>
</data>
I am tyring to use SimpleXML to retrieve an array containing "Apple, Orange, Banana". The code I am using is as follows:
$xml=simplexml_load_file('food.xml');
foreach($xml as $fruits=>$item) {
$foodlist[] = $item;
}
print_r($foodlist); // Should display list of fruits.
But the list of fruits is not being stored to the array. What am I doing wrong?
Much thanks.