【发布时间】:2013-12-09 12:58:54
【问题描述】:
$data = simplexml_load_file($source_url);
如果我正在循环浏览一些看起来像这样的项目
[item] => Array
(
[0] => SimpleXMLElement Object
(
[title] => Justin Bieber and Chance the Rapper Collaborate
[link] => http://feedproxy.google.com/~r/absolutepunknet/~3/vn98Mqyr4_4/showthread.php
[pubDate] => Mon, 09 Dec 2013 07:37:44 GMT
[description] => SimpleXMLElement Object
(
)
[category] => News
[guid] => http://www.absolutepunk.net/showthread.php?t=3576311
)
[1] => SimpleXMLElement Object
(
[title] => SimpleXMLElement Object
(
)
[link] => http://feedproxy.google.com/~r/absolutepunknet/~3/IjS0KtTy8Ws/showthread.php
[pubDate] => Mon, 09 Dec 2013 07:06:56 GMT
[description] => SimpleXMLElement Object
(
)
[category] => News
[guid] => http://www.absolutepunk.net/showthread.php?t=3576281
)
使用
foreach ($data->channel->item as $key => $value)
如何访问并可能删除其中一个对象,在此示例中,我想删除 [1] => SimpleXMLElementOjbect
我尝试过使用 $key 的值,但它只包含单词“item”。这个不太清楚。
【问题讨论】:
-
unset($data->channel->item[$key])在foreach内部工作吗?