如何在多维数组中获取特定值?

时间:2022-09-03 07:11:26

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?

我已经尝试过json_decode($ scope,true),$ scope ['installed'],$ scope ['data'] ['installed']等等。我错过了什么?

2 个解决方案

#1


2  

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.

这是一个超级嵌套的数组 - 你的$ scope ['data'] ['installed']接近了。但是,你忘了一层。它应该是$ scope ['data'] [0] ['installed']。注意那里的0 - 有第三级。

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.

访问任何范围将从$ scope ['data'] [0]开始,因此我将其分配给新的var以删除这两个层。

$scope = $scope['data'][0]

Then, all you need is the key for the permission

然后,您需要的只是许可的关键

#2


1  

Try $scope['data'][0]['installed']

试试$ scope ['data'] [0] ['installed']

#1


2  

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.

这是一个超级嵌套的数组 - 你的$ scope ['data'] ['installed']接近了。但是,你忘了一层。它应该是$ scope ['data'] [0] ['installed']。注意那里的0 - 有第三级。

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.

访问任何范围将从$ scope ['data'] [0]开始,因此我将其分配给新的var以删除这两个层。

$scope = $scope['data'][0]

Then, all you need is the key for the permission

然后,您需要的只是许可的关键

#2


1  

Try $scope['data'][0]['installed']

试试$ scope ['data'] [0] ['installed']