过滤xml数据无效

时间:2017-07-22 23:34:07

标签: php 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);

1 个答案:

答案 0 :(得分:3)

array_push方法无效。

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

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

相关问题