Ricardo Ricardo - 4 months ago 27
JSON Question

How to properly extract an Array from a cURL JSON?

I'm trying to extract a user profile picture from Instagram but I can't manage to successfully

the needed Array.


// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
// Closing

$result = json_decode($json, true);

echo $result[0]["profile-picture"];

I'm getting:
Notice: Undefined offset: 0 in test.php on line 23

Also tried to exclude the 2nd JSON parameter (
) and it didn't help.


The JSON for above URL is as follows:


So, you need to adjust your grip to this:


This will output


Go back one level in the tree to get user property with all its children

$user = $results['items'][0]['user'];