I'm trying to use unset()
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:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<user>
<name>Test Name 1</name>
<email>test@test.com</email>
<spouse/>
</user>
<user>
<name>Test Name 2</name>
<email>anotherone@test.com</email>
<spouse>Test Name 3</spouse>
</user>
</data>
My loop that I'm using is like this:
url = 'data/users.xml';
$xml = simplexml_load_file($url);
foreach($xml->user as $theUser){
if($theUser->email[0]=="test@test.com"){
echo "test";
unset($theUser);
}
}
When the e-mail matches "test@test.com" I want to be able to delete that whole user
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!