本文介绍了PHP的foreach数组对象stdClass已经的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助想进去阵列和stdClass的对象值。
FYI:我使用Foursquare的API ...
我有这样的事情:
`$ fsq_groups = $ venues->响应 - 基团;` 回声< pre>中;
的print_r($ fsq_groups);
回声< / pre>中;
从的print_r($ fsq_groups);
阵列
(
[0] => stdClass的对象
(
[类型] = GT;推荐地点
[名] =>推荐的
[项目] =>排列
(
[0] => stdClass的对象
(
[原因] => stdClass的对象
(
[计] => 2
[项目] =>排列
(
[0] => stdClass的对象
(
[类型] = GT;一般
[消息] =>很多人都提到的汉堡包在这里
) [1] => stdClass的对象
(
[类型] = GT;一般
[消息] =>这点是Foursquare的流行
) ) ) [地点] => stdClass的对象
(
[ID] => 4afe5a4bf964a520372f22e3
[名] =>粗壮的汉堡和放大器;啤酒
[联系方式] => stdClass的对象
...
我怎么到名称
在地点
我想这样的事情,但没有工作:
的foreach($ fsq_groups为$组)
{
的foreach($组 - >&物品─GT;场地为$场地)
{ 回声$ venue->名;
回声< pre>中;
的print_r($场地);
回声< / pre>中;
}
}
解决方案
$ fsq_groups = $ venues->响应 - 基团;
如果(使用isset($ fsq_groups [0])){
$组= $ fsq_groups [0];
的foreach($组 - >项目为$关键=> $的地方){
$场地= $占位>地点;
回声$ venue->名;
}
}
I need help trying to get values inside array and stdClass Object.
FYI: I'm using foursquare API...
I have something like this:
`$fsq_groups = $venues->response->groups;`
echo "<pre>";
print_r($fsq_groups);
echo "</pre>";
From print_r($fsq_groups);
Array
(
[0] => stdClass Object
(
[type] => Recommended Places
[name] => recommended
[items] => Array
(
[0] => stdClass Object
(
[reasons] => stdClass Object
(
[count] => 2
[items] => Array
(
[0] => stdClass Object
(
[type] => general
[message] => Lots of people have mentioned "burgers" here
)
[1] => stdClass Object
(
[type] => general
[message] => This spot is popular on Foursquare
)
)
)
[venue] => stdClass Object
(
[id] => 4afe5a4bf964a520372f22e3
[name] => Stout Burgers & Beer
[contact] => stdClass Object
...
How do I get to the name
under venue
I tried something like this but didn't work:
foreach($fsq_groups as $groups)
{
foreach($groups->items->venue as $venue)
{
echo $venue->name;
echo "<pre>";
print_r($venue);
echo "</pre>";
}
}
解决方案
$fsq_groups = $venues->response->groups;
if(isset($fsq_groups[0])){
$groups = $fsq_groups[0];
foreach($groups->items as $key => $place){
$venue = $place->venue;
echo $venue->name;
}
}
这篇关于PHP的foreach数组对象stdClass已经的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!