Looping through identically named elements with foreach() : Array Loop « Data Structure « PHP






Looping through identically named elements with foreach()

 
<?
$menu=<<<_XML_
<?xml version="1.0" encoding="utf-8" ?>
<rss version="0.91">
 <channel>
  <title>What's For 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 as $item) {
    print "Title: " . $item->title . "\n";
}
?>
  
  








Related examples in the same category

1.Using foreach to Iterate through an Array
2.Looping through an Enumerated Array
3.Looping Through a Compact Indexed Array Using for and count()
4.Looping Through a Multidimensional Array
5.Looping Through a Sparse Array
6.Looping Through an Associative Array with foreach
7.Looping Through the $_SERVER Array
8.Looping through child elements with foreach()
9.Looping with foreach()
10.List array values