【问题标题】:How can I access nested arrays item php如何访问嵌套数组项 php
【发布时间】:2012-04-07 07:55:53
【问题描述】:

我正在使用 PHP 开发应用程序。一些示例代码在这里。

$url = "http://localhost:8080/?Xml";

$xml = simplexml_load_file($url);

foreach($xml->result->doc as $doc){
echo "<pre>".print_r($doc)."</pre>";
}

其中一个是我要求的。

SimpleXMLElement Object ( [@attributes] => Array ( [score] => 4.112774 [pos] => 0 ) [field] => Array ( [0] => http://www.w3schools.com/htmldom/dom_examples.asp [1] => text/html [2] => Free HTML XHTML CSS JavaScript jQuery XML DOM XSL XSLT RSS AJAX ASP .NET PHP SQL tutorials, references, examples for web building. [3] => html,css,tutorial,html5,dhtml,css3,xsl,xslt,xhtml,javascript [4] => www.w3schools.com [5] => en ) [snippet] => Array ( [0] => DOM Examples [1] => DOM HOME DOM Intro DOM Nodes DOM Node Tree DOM Methods DOM Node Access DOM Node Info DOM How To DOM Events DOM Summary DOM... ) ) 

我想知道如何访问数组项?

【问题讨论】:

标签: php arrays xml-parsing


【解决方案1】:
foreach($doc->attributes() as $key => $value) {
    echo "$key: $value\n";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-05-08
    • 1970-01-01
    • 2018-08-16
    • 2017-03-27
    • 2017-06-19
    • 2020-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多