Mega Code Archive

 
Categories / Php / Data Type
 

Looping through child elements with foreach()

<? $menu=<<<_XML_ <?xml version="1.0" encoding="utf-8" ?> <rss version="0.91">  <channel>   <title>Dinner</title>   <link>http://example.com/</link>   <description>choices</description>   <item>    <title>Feet</title>    <link>http://example.com</link>    <description>test</description>   </item>  </channel> </rss> _XML_; $xml = simplexml_load_string($menu); foreach ($xml->channel->item[0] as $element_name => $content) {     print "The $element_name is $content\n"; } ?>