筛选 xml 数据不起作用



我使用外部xml,这有效,但我有另一个问题。在我的__construct中,我有$elem负责过滤xml数据。但它不起作用。请帮忙。我不知道怎么咬它。

class  Property {
public $xmlClass;
public $array = [];
public $elem = '';
public function __construct($xml,$elem) {
$this->xmlClass=$xml;
foreach($xml->list->film->$elem as $result) {
$array = array_push($result);
}
}
}


$result_scenario = new Property($xml,'scenario');
print_r($result_scenario);

array_push方法不是这样工作的。

您需要将数组作为第一个参数传递,而不是传递要推送的元素。在您的情况下,这将是array_push($this->array, $result);.该函数返回数组中新的元素数。

请参阅此处的文档 http://php.net/manual/en/function.array-push.php

最新更新