title: How to get PHP simple XML value with child node?
body: <p>I have an XML as shown. I Need to iterate through the  tags with for each loop and pull out the attributes <code>attr1</code>. But I'm constantly getting <code>"Illegal string offset"</code>.</p>
  
  <p>My data:</p>
  
  <pre><code>&lt;Parent&gt;
    &lt;Child&gt;
      &lt;ID attr1="123" attr2="567"&gt;abc&lt;/ID&gt;
      &lt;ID attr1="123" attr2="567"&gt;abc&lt;/ID&gt;
    &lt;/Child&gt;
  &lt;/Parent&gt;
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>foreach ($parentNode-&gt;Child-&gt;ID as $IDChild =&gt; $value)
  {
      echo $value; // does this output "abc"?
      echo $IDChild['attr1']; // need to display "123", but throwing error.
      $IDChild['attr1'] = "999"; // also need to update the value in the xml
  }
  </code></pre>