title: PHP - Remove children with a specific attribute in php
body: <blockquote>
    <p>The goal is to delete every XML child with the same parent that matches the id.</p>
  </blockquote>
  
  <p><strong>The problem I've encountered was that only the first XML child was removed</strong>. When I ran this file the output was "The id is: 1" and also "CarlCarlok". The script removed the first XML child with the attribute "1". Which also was proven when I checked the XML file afterwards where the comment with id "9" was removed. So..To resolve this issue i have to know:</p>
  
  <blockquote>
    <p>How do I remove every XML child with the same parent?
    <em>Because now it only removes the first one it encounters.</em></p>
  </blockquote>
  
  <pre><code>&lt;?php
  require '../functions.php';
  
  $id = $_GET['id'];
  echo "The id is: " . $id . "\n";
  
  $comment_xml_path = '../data/comments.xml';
  $comments_xml_file = simplexml_load_file($comment_xml_path);
  
  foreach ($comments_xml_file-&gt;comment as $c) {
      echo $c-&gt;author;
      if (strcmp($id, $c['parent']) == 0) {
          $dom = dom_import_simplexml($c);
          $dom-&gt;parentNode-&gt;removeChild($dom);
          echo "ok";
      }
      save_xml($comment_xml_path, $comments_xml_file);
  </code></pre>
  
  <p>(save_xml() is a function for saving utilizing asXML that we made during class)</p>
  
  <p><strong>The XML file</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;comments&gt;
      &lt;comment id="6" parent="3" date="20150317224217"&gt;
           &lt;author&gt;Carl&lt;/author&gt;
           &lt;cmt&gt;3&lt;/cmt&gt;
      &lt;/comment&gt;
      &lt;comment id="9" parent="1" date="20150312225112"&gt;
           &lt;author&gt;Carl&lt;/author&gt;
           &lt;cmt&gt;dsa&lt;/cmt&gt;
      &lt;/comment&gt;
      &lt;comment id="10" parent="1" date="20150356225256"&gt;
           &lt;author&gt;Carl&lt;/author&gt;
           &lt;cmt&gt;2&lt;/cmt&gt;
      &lt;/comment&gt;
      &lt;comment id="11" parent="1" date="20150357225257"&gt;
           &lt;author&gt;Carl&lt;/author&gt;
           &lt;cmt&gt;2&lt;/cmt&gt;
      &lt;/comment&gt;
  &lt;/comments&gt;
  </code></pre>