How do I get a particular value in a multidimensional array?
How do I prase this?
$scope = $facebook->api('/me/permissions','GET');
The result is as开发者_JS百科 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?
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.
$scope = $scope['data'][0]
Then, all you need is the key for the permission
Try $scope['data'][0]['installed']
精彩评论