0

所以我知道我将尝试删除的节点的确切路径。我正在遍历几个 xml 文件以更新一些内容。为了添加一些新的内容,我必须先删除已经存在的内容。

这是我尝试使用的代码,但我收到 Parse 错误:语法错误,意外 T_UNSET

public function hint_insert() {

    foreach($this->hints as $key => $value) {

        $filename = $this->get_qid_filename($key);

        echo "$key - $filename - $value[0]<br>";

        //insert hint within right node using simplexml
        $xml = simplexml_load_file($filename);

        foreach ($xml->PrintQuestion as $PrintQuestion) {

            if (unset($xml->PrintQuestion->content->multichoice->feedback->hint->Passage)) {

                $xml->PrintQuestion->content->multichoice->feedback->hint->addChild('Passage', $value[0]);

            } else {

                $xml->PrintQuestion->content->multichoice->feedback->hint->addChild('Passage', $value[0]);

            }

        }

    }
4

1 回答 1

0

unset是一种语言结构,您不能在if语句中使用它。如果您在语句之外使用它if/不要期望它返回任何内容,那么您应该没问题。

于 2010-08-05T19:14:43.813 回答