I've got a foreach loop that is only running once and it has me stumped.
1: I load an array of status values (either "request", "delete", or "purchased")
2: I then load an XML file and need to loop through the "code" nodes and update their status, but if the new code is "delete" I want to remove it before moving onto the next one
The XML structure is...
<content>
.... lots of stuff
<codes>
<code date="xxx" status="request">xxxxx</code>
.. repeat ...
</codes>
</content>
And the PHP code is...
$newstatus = $_POST['updates'];
$file = '../apps/templates/' . $folder . '/layout.xml';
$xml2 = simplexml_load_file($file);
foreach($xml2->codes->code as $code) {
if($code['status'] == "delete") {
$dom = dom_import_simplexml($code);
$dom->parentNode->removeChild($dom);
}
}
$xml2->asXml($file);
I've temporarily removed the updating, so I can debug the delete check.
This all works, but it only removes the first delete and leaves all the other deletes even though it's a foreach loop?