如何获取多维数组中的特定值?
我该如何赞美这个?
$scope = $facebook->api('/me/permissions','GET');
结果如下,我想获取installed的值:
array(1) { ["data"]=> array(1) { [0]=> array(5) { ["installed"]=> int(1) ["offline_access"]=> int(1) ["email"]=> int(1) ["manage_pages"]=> int(1) ["user_about_me"]=> int(1) } } }
我试过json_decode($scope, true)
,$scope['installed' ]
、$scope['data']['installed']
等。我缺少什么?
How do I prase this?
$scope = $facebook->api('/me/permissions','GET');
The result is as follows and I want to get the value of installed:
array(1) { ["data"]=> array(1) { [0]=> array(5) { ["installed"]=> int(1) ["offline_access"]=> int(1) ["email"]=> int(1) ["manage_pages"]=> int(1) ["user_about_me"]=> int(1) } } }
I've tried json_decode($scope, true)
, $scope['installed']
, $scope['data']['installed']
etc. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个超级嵌套数组 - 您的 $scope['data']['installed'] 很接近。然而,你忘记了一层。它应该是 $scope['data'][0]['installed']。请注意其中的 0 - 还有第三级。
访问任何范围都将从 $scope['data'][0] 开始,因此我会将其分配给一个新的 var 以删除这两层。
然后,您所需要的只是权限的密钥
That is a super nested array - Your $scope['data']['installed'] was close. However, you forgot one layer. It should be $scope['data'][0]['installed']. Note the 0 in there - there is a third level.
Accessing any of the scope will start with $scope['data'][0], so I would assign that to a new var to remove those two layers.
Then, all you need is the key for the permission
尝试
$scope['data'][0]['installed']
Try
$scope['data'][0]['installed']