title: PHP Accessing SimpleXMLElement Object array keys
body: <p>In the following SimpleXMLElement Object <code>$results</code>, I would like to remove the element with ID <code>13011146</code> from the TEST array. I'm not sure how to properly access the array key with value <code>1</code>, so I'm using a counter <code>$i</code>, but that gives me an error <code>Node no longer exists</code>, pointing to the foreach line.</p>
  
  <p><strong>TL;DR</strong>: How do you unset <code>$result-&gt;TEST[1]</code> ?</p>
  
  <pre><code>SimpleXMLElement Object
  (
      [TEST] =&gt; Array
          (
              [0] =&gt; SimpleXMLElement Object
                  (
                      [@attributes] =&gt; Array
                          (
                              [ID] =&gt; 13011145
                          )
  
                  )
  
              [1] =&gt; SimpleXMLElement Object
                  (
                      [@attributes] =&gt; Array
                          (
                              [ID] =&gt; 13011146
                          )
  
                  )
          )
  
  )
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>$i = 0;
  foreach($results-&gt;TEST as $key =&gt; $value) {
      if( (string)$value['ID'] == 13011146 ) {
          unset($results-&gt;TEST[$i]);
      }
      $i++;
  }
  </code></pre>