【发布时间】:2011-05-12 22:58:11
【问题描述】:
我需要回显一个数组的键值。
这就是我输出数组的方式:
foreach($xml->channel->item as $item) {
$item->title
}
我已经尝试添加:
foreach($xml->channel->item as $key => $item)
但我回显的值是:item
有什么想法吗?
项目结果的变量转储:
var_dump($xml->channel->item);
object(SimpleXMLElement)#4 (5) {
["title"]=> string(33) "BA and union agree to end dispute"
["description"]=> string(118) "British Airways and the Unite union reach an agreement which could end the long-running dispute between the two sides."
["link"]=> string(61) "http://www.bbc.co.uk/go/rss/int/news/-/news/business-13373638"
["guid"]=> string(43) "http://www.bbc.co.uk/news/business-13373638"
["pubDate"]=> string(29) "Thu, 12 May 2011 12:33:38 GMT"
}
【问题讨论】:
-
你把
echo放在$item->title前面了吗?尝试var_dump($xml->channel->item并调试它是否已经是array。 -
我认为它是一个 SimpleXML 对象,不一定会作为数组转储
标签: php