我有这个代码用于解析XML URL并将输出存储在$查询变量中。具有simplexml对象的数组。如何使用foreach循环获取它
$url = 'http://www.slideshare.net/api/2/search_slideshows?api_key=GRCsS0fPo&
ts=1320547556&hash=cf362f863d1f15e84c7a520804f7826731f958c4&q=electrical+engineering&
page=4&download=0&items_per_page=25';
echo $url;
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Your application name');
$query = curl_exec($ch);
curl_close($ch);
$array = (array) simplexml_load_string($query);
echo '<pre>';
print_r($array);
当我打印使用的print_r($阵列)这个数组它给了我
Array
(
[Meta] => SimpleXMLElement Object
(
[Query] => php programming
[ResultOffset] => SimpleXMLElement Object
(
)
[NumResults] => 25
[TotalResults] => 36839
)
[Slideshow] => Array
(
[0] => SimpleXMLElement Object
(
[ID] => 1966058
[Title] => title here
[Description] => description here
[Status] => 2
[Username] =>usrname
[URL] => url here
[ThumbnailURL] => a url
[ThumbnailSmallURL] => a url
[Embed] => some embed code
)
[1] => SimpleXMLElement Object
(
[ID] => 1966058
[Title] => title here
[Description] => description here
[Status] => 2
[Username] =>usrname
[URL] => url here
[ThumbnailURL] => a url
[ThumbnailSmallURL] => a url
[Embed] => some embed code
)
现在我想取这个数组并使用它的每一个值。我想要这个数组的所有节点值。所以如何使用foreach循环获取这个数组。
重复http://stackoverflow.com/questions/8023179/how-to-fetch-this-array-using-foreach-loop – Vikk