php – 回显SimpleXMLElement对象

我有一个看起来像这样的数组.

Array
(
    [@attributes] => Array
        (
            [version] => 2.0
        )

    [channel] => SimpleXMLElement Object
        (
            

=> Active Fire Incident Page [link] => http://www.ci.austin.tx.us/fact/default.cfm [description] => This page provides information on active Austin/Travis County Fire incidents. Data is updated every 3 minutes. [lastBuildDate] => Wed, 23 Nov 2016 10:59:38 PM GMT [copyright] => 2016 City of Austin. All rights reserved. [language] => en-us [item] => SimpleXMLElement Object (

=> E ST ELMO RD/SHERATON AVE [link] => http://www.ci.austin.tx.us/fact/default.cfm [description] => AFD - 4700 S Congress Ave - BOX -Structure Fire - Wed, 23 Nov 2016 10:51 PM [pubdate] => Wed, 23 Nov 2016 10:51 PM ) ) )

我如何回应数组的最后部分?这个部分:

                    

=> E ST ELMO RD/SHERATON AVE [link] => http://www.ci.austin.tx.us/fact/default.cfm [description] => AFD - 4700 S Congress Ave - BOX -Structure Fire - Wed, 23 Nov 2016 10:51 PM [pubdate] => Wed, 23 Nov 2016 10:51 PM

使用此代码:

echo $xml->channel->item->link;

我越来越

Notice:Trying to get property of non-object

最佳答案 你使用错误的代码,试试这个

foreach($xml->channel->item as $key => $product){
   echo $product->link;

或直接

 echo $xml->channel->item->link;
点赞