如何在迭代时删除SimpleXMLElement? (PHP)

时间:2015-07-23 18:57:59

标签: php

我在XML结构中加载并运行一个循环:

$xml = simplexml_load_file(flakk);
foreach ($xml->class as $class)
{
    now how to delete $class ???
}

unset($class)无效。

1 个答案:

答案 0 :(得分:0)

你不能删除foreach元素,但例如可以

for($i=count($xml->class); $i--; ) unset($xml->class[$i]);

for($i=count($xml->class); $i--; )  
   if ($xml->class[$i] == AnyValue)   
       unset($xml->class[$i]);
相关问题