0

How to get instagram_business_id (id) if its there? Enable to get it, undefined index instagram_business_id error

    $pages = '[
  {
    "access_token": "",
    "instagram_business_account": {
      "id": "123"
    },
    "name": "Page Name",
    "id": "XXX"
  },
  {
    "access_token": "",
    "name": "Page Name2",
    "id": "XXX"
  }
]';

Loop
foreach($pages as $page){

}
Zack
  • 171
  • 2
  • 12
  • try `$pages = json_decode($pages);` – Mickaël Leger Aug 07 '18 at 08:23
  • Try this after the `$pages = json_decode($pages)` : `foreach ($pages as $key => $obj) { if (isset($obj->instagram_business_account)) { $instagram = $obj->instagram_business_account; if (isset($instagram->id)) { echo $instagram->id; } } }` – Mickaël Leger Aug 07 '18 at 08:32

1 Answers1

0

Check this below code $res = json_decode($pages, true);

print_r($res[0]['instagram_business_account']);

Sachin
  • 397
  • 4
  • 13