我需要回顯數組的鍵值。PHP - 數組項的回顯鍵值
這是怎麼IM輸出我的數組:
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'在'$用品 - > title'的面前?嘗試'var_dump($ xml-> channel-> item'並調試它是否已經是'array'或不是。 – 2011-05-12 22:59:19
我認爲這是一個SimpleXML對象,不一定會作爲數組轉儲出來 – 2011-05-12 23:00:57