如何使用foreach循环来获取这个数组
问题描述:
我有一个多维数组。该阵列是使用卷曲解析XML返回。当卷曲给我的输出我转换输出到数组使用$阵列=(阵列)simplexml_load_string($查询);和$阵列如下。现在,我想用foreach循环来获取这个数组和想要的一切,从这个阵列
i have a multidimensional array. the array is returned by parsing xml using curl. when curl gave me the output i converted the output into array using $array = (array) simplexml_load_string($query); and the $array is given below. Now i want to fetch this array using foreach loop and want everything from this array
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:
You can retrieve meta information without using foreach:
echo $array['Meta']->Query;
echo $array['Meta']->NumResults;
等等...
要获取幻灯片:
foreach($array['Slideshow'] as $slideshow)
{
echo $slideshow->ID;
echo $slideshow->Title;
//-- and so on...
}