$data = simplexml_load_file($source_url);
,如果我通过循环一些项目看起来像这样PHP - 如何从一个XML对象获取foreach循环内的关键数字
[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'里面工作吗? –