I have a code that removes only the xml tags that expired and list the other tags, but if one tag expired it will delete it and stop the foreach loop execution without listing the other tags. if I reload the page after the code finished removing the expired tag it will list the other tags normally without any problem. how can I make it continue to list the other tags?
php code:
$xml_file = simplexml_load_file("xml_file.xml");
foreach ($xml_file as $item)
{
$current_date = time();
$article_date = (int)$item->date;
$item_number = (int)str_replace("a" , "" ,$item->getName());
if ($current_date >= $article_date + 100000)
{
if ($item->children()->getName() == "a")
{
$dom = dom_import_simplexml($item);
$dom->parentNode->removeChild($dom);
$return = simplexml_import_dom($dom);
$xml_file->asXML('xml_file.xml');
unlink('file.html');
}
}
elseif ($current_date < $article_date + 100000)
{
echo 'hello';
}
}
xml code:
<articles>
<a1><a>gr</a><date>14</date></a1>
<a2><a>gr</a><date>1414141414141414</date></a2>
<a3><a>gr</a><date>1414141414141414</date></a3></articles>
this code should remove the first tag and print hello twice, but it just removes the first tag and stop the foreach loop execution without printing any thing, and if I reload the page after deleting the first tag it prints hello twice without any problem.