title: Using unset() to delete node in XML; PHP/simplexml_load_file
body: <p>I'm trying to use <code>unset()</code> to delete a node in an XML using PHP and can't figure out what is going on here. It doesn't seem to work correctly and I've seen a lot of other questions of similar nature on here but they don't seem to address this issue directly. Here's what my XML looks like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;data&gt;
      &lt;user&gt;
          &lt;name&gt;Test Name 1&lt;/name&gt;
          &lt;email&gt;test@test.com&lt;/email&gt;
          &lt;spouse/&gt;
      &lt;/user&gt;
      &lt;user&gt;
          &lt;name&gt;Test Name 2&lt;/name&gt;
          &lt;email&gt;anotherone@test.com&lt;/email&gt;
          &lt;spouse&gt;Test Name 3&lt;/spouse&gt;
      &lt;/user&gt;
  &lt;/data&gt;    
  </code></pre>
  
  <p>My loop that I'm using is like this:</p>
  
  <pre><code>url = 'data/users.xml';
  $xml = simplexml_load_file($url);
  
  foreach($xml-&gt;user as $theUser){
      if($theUser-&gt;email[0]=="test@test.com"){
          echo "test";
          unset($theUser);
      }
  }
  </code></pre>
  
  <p>When the e-mail matches "test@test.com" I want to be able to delete that whole <code>user</code> node. It seems that this should work but I can't figure out why it wouldn't? Any help would be greatly appreciated. Thank you!</p>