0

I'm receiving the JSON array below with various permissions. How to check the publish_actions [status] value if you don't know which node it is in? (currently it's in [3] but it could be any other number)

JSON array:

Array (
    [data] => Array (
        [0] => Array (
            [permission] => installed
            [status] => granted
        )
        [1] => Array (
            [permission] => public_profile
            [status] => granted
        )
        [2] => Array (
            [permission] => manage_pages
            [status] => granted
        )
        [3] => Array (
            [permission] => publish_actions
            [status] => granted
        )
        [4] => Array (
            [permission] => user_groups
            [status] => granted
        )
    )
)

2 Answers 2

2

Use json_decode and then iterate the array:

$publish_actions_status = '';
$array=json_decode($json_string);
foreach($array['data'] as $node){
    if($node['permission']=='publish_actions'){
        $publish_actions_status = $node['status'];
        break;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try

foreach($data as $k=>$v) {
  if($v['permission']=='publish_actions'){
    $newarr[]['permission'] = $v['permission'];
    $newarr[]['status'] = $v['status']
  }
}
print_r($newarr);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.