title: PHP Array cURL foreach
body: <p>I have again a problem, I want to use in ShoutCast2 the API and have an array a problem.</p>
  
  <pre><code>$sc_host = 'IP';
  $sc_port = 'PORT';
  $sc_user = 'USER';
  $sc_pass = 'PASSWORD';
  mt_srand((double) microtime() * 1000000);
  $seq  = mt_rand(1, 100);
  $post = 'op=listevents&amp;seq=' . $seq;
  $ch   = curl_init($sc_host . '/api');
  curl_setopt($ch, CURLOPT_PORT, $sc_port);
  curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, $sc_user . ':' . $sc_pass);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  $curl = curl_exec($ch);
  $xml  = new SimpleXMLElement(utf8_encode($curl));
  curl_close($ch);
  </code></pre>
  
  <p>Array Output:</p>
  
  <pre><code>Array (
      [@attributes] =&gt; Array (
          [seq] =&gt; 128
      )
      [data] =&gt; Array (
          [eventlist] =&gt; Array (
              [event] =&gt; Array (
                  [@attributes] =&gt; Array (
                      [type] =&gt; relay
                  )
                  [relay] =&gt; Array (
                      [@attributes] =&gt; Array (
                          [priority] =&gt; 1
                          [url] =&gt; IP:PORT
                      )
                  )
                  [active] =&gt; 1
                  [id] =&gt; 1
                  [calendar] =&gt; Array (
                      [@attributes] =&gt; Array (
                          [starttime] =&gt; 00:00:00
                      )
                  )
              )
          )
      )
  )
  </code></pre>
  
  <p>Now I want to read the output via array:</p>
  
  <pre><code>foreach ($xml-&gt;data-&gt;eventlist-&gt;event as $event ) {
  
          echo $event -&gt;type;
  
  
      }
  </code></pre>
  
  <p>no issue is why? where is the error?</p>
  
  <p>Thank you</p>
  
  <p>EDIT ORIGINAL XML</p>
  
  <pre><code>&lt;eventlist&gt;
   &lt;event type="playlist|dj|relay"&gt;
     &lt;active/&gt;
     &lt;id/&gt;
     &lt;dj/&gt;
     &lt;playlist loopatend="1|0" shuffle="1|0" priority="#"&gt;
       nameofplaylist
     &lt;/playlist&gt;
     &lt;relay url=""/&gt;
     &lt;calendar/&gt;
   &lt;/event&gt;
   &lt;event ... /&gt;
  </code></pre>
  
  <p></p>