I am having problems unsetting a SimpleXML node when using a variable index instead of a numerical one.
Here is my code that calls the simpleXML:
$highlights = new SimpleXMLElement($prj['project_xmldata']);
$node=$_POST['node'];
if(count($highlights->highlights->highlight)>0) {
unset($highlights->highlights->highlight[$node]);
print_r($highlights);
}
The contents of the print_r statement still shows the original XML data. however, if I were do unset the node using a numeric index instead of the variable $node I get the correct response, with the removal of the node I unset.
I’ve tried encapsulating the variable with double quotes as well, and made sure the $_POST[‘node’] is a correct value. Am I doing something wrong, or can I not put a variable inside square braces?
Change your code to this and let me know what it says:
Make sure that node is correct. Make sure that it is being registered as an int and not a string.
$variable[0] is different than $variable[“0”]