title: How to index XML elements in PHP?
body: <p>I am dummy to PHP and XML, so please be patient if my question seems dumb.</p>
  
  <p>I want to know how to index the XML elements so that I can access them. I am planning to put them into an array. However, I don't know how to get the number of elements returned.</p>
  
  <p>Here are the codes:</p>
  
  <p><b><code>exer.xml</code></b></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  
  &lt;actionstars&gt;
   &lt;name&gt;Jean Claude Van Damme&lt;/name&gt;
   &lt;name&gt;Scott Adkins&lt;/name&gt;
   &lt;name&gt;Michael Jai White&lt;/name&gt;
   &lt;name&gt;Dolph Lundgren&lt;/name&gt;
   &lt;name&gt;Tom Cruise&lt;/name&gt;
   &lt;name&gt;Michael Worth&lt;/name&gt;
  &lt;/actionstars&gt;
  </code></pre>
  
  <p><b><code>index.php</code></b></p>
  
  <pre><code>&lt;?php
   $dom = new DomDocument();
   $dom-&gt;load("exer.xml");
   $names = $dom-&gt;getElementsByTagName("name");
   echo count($names);
   foreach($names as $name) {
       print $name-&gt;textContent . "&lt;br /&gt;";
   }
  ?&gt;
  </code></pre>
  
  <p>When I do the <code>echo count($names);</code> it returns <code>1</code>, which is obviously not the number of elements. Please help.</p>