title: PHP remove multiple elements with dom
body: <p>I'm trying to remove multiple elements in php using DOM Document, but it does not work as i wanted it to work. </p>
  
  <pre><code>&lt;iPhone&gt;
  &lt;enAttentePush&gt;
    &lt;UDID&gt;dd6fc8032f0bf4c4b3a9c60f523900c9ad463b620a83b6473eda9a12b2c9d47f&lt;/UDID&gt;
    &lt;Message&gt;someDataHere&lt;/Message&gt;
  &lt;/enAttentePush&gt;
  
  &lt;enAttentePush&gt;
    &lt;UDID&gt;dd6fc8032f0bf4c4b3a9c60f523900c9ad463b620a83b6473eda9a12b2c9d47f&lt;/UDID&gt;
    &lt;Message&gt;someDataHere&lt;/Message&gt;
  &lt;/enAttentePush&gt;
  &lt;/iPhone&gt;
  </code></pre>
  
  <p>I want to loop into my xml document and then erase all element to get an empty file. </p>
  
  <p>Here is what i do in php : </p>
  
  <pre><code>$doc = new DOMDocument;
  
  $doc-&gt;load('$myFile'); 
  $domNodeList = $doc-&gt;getElementsByTagName('enAttentePush'); 
  $arraySeen = array(); 
  $arrayBug = array(); 
  
  foreach ($domNodeList as $domElement)
  {
          //echo('loop / ');
    $tempArray = array(); 
  
    $aps = $domElement-&gt;getElementsByTagName('Message')-&gt;item(0)-&gt;nodeValue;
    $udid = $domElement-&gt;getElementsByTagName('UDID')-&gt;item(0)-&gt;nodeValue; 
    if (!in_array($udid, $arraySeen))
    {         
        $tempArray[]=$aps; 
        $tempArray[]=$udid; 
        $arrayBug[]=$tempArray;
       $arraySeen[]=$udid; 
     }
  
     echo("-- removed -- ");
     $domElement-&gt;parentNode-&gt;removeChild($domElement); 
    }
  </code></pre>
  
  <p>It only delete only one node, the last one in general. </p>
  
  <p>How can i do to loop thought my node and remove it each time i see a node ? </p>
  
  <p>Thank you very much.</p>