Reputation: 23989
I have the following example JSON data:
Array ( [data] => Array ( [0] => Array ( [name] => Jonathan James[id] => 45879) [1] => Array ( [name] => Jackson C. Gomez [id] => 989) [2] => Array ( [name] => Liz Mack [id] => 787)... etc etc
I'm trying to loop through it and pull the name and the ID but returning nothing, here's the code I'm trying:
$friendsList = json_decode(file_get_contents('https://graph.facebook.com/'.$fb_user.'/friends?access_token='.$access_token),true);
foreach ($friendsList as $element){
echo $element[name].' - '.$element[id];
}
Do I have to drill deeper into the JSON and if so how?
Upvotes: 0
Views: 35
Reputation: 10975
Please try this:
<?php
$friendsList = array(
'data' => array(
array('name' => 'Jonathan James', 'id' => 45879),
array('name' => 'Jackson C. Gomez', 'id' => 989),
array('name' => 'Liz Mack', 'id' => 787)
)
);
foreach ($friendsList['data'] as $element){
echo $element['name'].' - '.$element['id']."<br>\n";
}
?>
Upvotes: 1