title: XML Assign More Than One Result To PHP Variable
body: <p>I have done a bit of searching on this, but am just not sure I am searching for the right thing. Examples and things I have found have just confused me and possibly sent me in the wrong direction.</p>
  
  <p>I am trying to figure out a php while statement, or if statement to return the results of XML output. The thing is the row/section I need may not always be the same number of results returned. For example there are ShoutCast streams, some have 1 mount point, and some have 3 mount points. Each mount point can have a different amount of listeners tuned in to that particular mount. </p>
  
  <p>My Goal: To get the integer from all mount points returned in the XML, add them together to make a grand total of listeners.</p>
  
  <p>The XML</p>
  
  <pre><code>&lt;centovacast version="3.1.2" host="host.net"&gt;
  &lt;response type="success"&gt;
  &lt;message&gt;Complete&lt;/message&gt;
  &lt;data&gt;
  &lt;status&gt;
  &lt;mount&gt;/stream&lt;/mount&gt;
  &lt;sid&gt;1&lt;/sid&gt;
  &lt;listenercount&gt;31&lt;/listenercount&gt;
  &lt;genre&gt;Blues&lt;/genre&gt;
  &lt;url&gt;http://www.websiteurl.com&lt;/url&gt;
  &lt;title&gt;Streams Name&lt;/title&gt;
  &lt;currentsong&gt;Artist Name - Track Name&lt;/currentsong&gt;
  &lt;bitrate&gt;128&lt;/bitrate&gt;
  &lt;sourceconnected&gt;1&lt;/sourceconnected&gt;
  &lt;codec&gt;audio/mpeg&lt;/codec&gt;
  &lt;displayname&gt;/stream&lt;/displayname&gt;
  &lt;serverstate&gt;1&lt;/serverstate&gt;
  &lt;appstate&gt;
  &lt;sctrans2&gt;1&lt;/sctrans2&gt;
  &lt;/appstate&gt;
  &lt;sourcestate&gt;1&lt;/sourcestate&gt;
  &lt;reseller/&gt;
  &lt;useserver&gt;1&lt;/useserver&gt;
  &lt;ipaddress&gt;11.11.111.111&lt;/ipaddress&gt;
  &lt;port&gt;8031&lt;/port&gt;
  &lt;proxy&gt;0&lt;/proxy&gt;
  &lt;servertype&gt;ShoutCast2&lt;/servertype&gt;
  &lt;sourcetype&gt;sctrans2&lt;/sourcetype&gt;
  &lt;/status&gt;
  &lt;mountpoints&gt;
  &lt;row&gt;
  &lt;mount&gt;/stream&lt;/mount&gt;
  &lt;sid&gt;1&lt;/sid&gt;
  &lt;listenercount&gt;31&lt;/listenercount&gt;
  &lt;genre&gt;Blues&lt;/genre&gt;
  &lt;url&gt;http://www.websiteurl.com&lt;/url&gt;
  &lt;title&gt;Stream Title Name&lt;/title&gt;
  &lt;currentsong&gt;Artist Name - Track Name&lt;/currentsong&gt;
  &lt;bitrate&gt;128&lt;/bitrate&gt;
  &lt;sourceconnected&gt;1&lt;/sourceconnected&gt;
  &lt;codec&gt;audio/mpeg&lt;/codec&gt;
  &lt;displayname&gt;/stream&lt;/displayname&gt;
  &lt;/row&gt;
  &lt;row&gt;
  &lt;mount&gt;/live&lt;/mount&gt;
  &lt;sid&gt;2&lt;/sid&gt;
  &lt;listenercount&gt;0&lt;/listenercount&gt;
  &lt;genre/&gt;
  &lt;url/&gt;
  &lt;title/&gt;
  &lt;currentsong/&gt;
  &lt;bitrate&gt;0&lt;/bitrate&gt;
  &lt;sourceconnected&gt;0&lt;/sourceconnected&gt;
  &lt;codec/&gt;
  &lt;displayname&gt;/live&lt;/displayname&gt;
  &lt;/row&gt;
  &lt;/mountpoints&gt;
  &lt;/data&gt;
  &lt;/response&gt;
  &lt;/centovacast&gt;
  </code></pre>
  
  <p>So on the above I know how to pull the listeners for each mount individually using the following code.</p>
  
  <pre><code>$countlisteners-&gt;response-&gt;data-&gt;mountpoints-&gt;row[0]-&gt;listenercount;
  </code></pre>
  
  <p>That gives me the result for the first mount, and switching the 0 to a 1 gives me the second mount, so on and so forth.</p>
  
  <p>What I need is for php that will count how many of those mounts exist, and assign each result to a variable I can then use to add together to get a grand total. Is there a way to do this? </p>
  
  <p>What about doing something like this?</p>
  
  <pre><code>$countlisteners = simplexml_load_file('http://urltoxml.com');
  foreach($countlisteners-&gt;response-&gt;data-&gt;mountpoints-&gt;row-&gt;listenercount as $result){
  $total = $result;
  echo $total;
  }
  </code></pre>