Easy PHP SimpleXML Issue

vtgohi8lis

New Member
I've got a really bad brain block with this.My XML file looks like this:\[code\]<?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>\[/code\]I am tyring to use SimpleXML to retrieve an array containing "Apple, Orange, Banana". The code I am using is as follows:\[code\]$xml=simplexml_load_file('food.xml');foreach($xml as $fruits=>$item) { $foodlist[] = $item;}print_r($foodlist); // Should display list of fruits.\[/code\]But the list of fruits is not being stored to the array. What am I doing wrong?Much thanks.
 
Back
Top