【问题标题】:Filtering the xml data is not working过滤 xml 数据不起作用
【发布时间】:2017-07-22 23:34:07
【问题描述】:

我使用外部 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);

【问题讨论】:

  • 而不是说“它不起作用”,您应该提供有关正在发生的事情的信息。例如,您是否收到错误消息?

标签: php xml


【解决方案1】:

array_push 方法不能这样工作。

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

在此处查看文档http://php.net/manual/en/function.array-push.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-20
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多