来自json的Foreach空

I have the following url:

https://graph.facebook.com/123456/likes?access_token=__ACCESS_TOKEN__&format=json

which I then do:

$likesList = json_decode(file_get_contents("https://graph.facebook.com/123456/likes?access_token=$access_token&format=json"),true);

which produces e.g.

{
"data": [

  {
     "name": "yo yo yo",
     "category": "Entertainer",
     "id": "45640987076",
     "created_time": "2012-04-18T16:14:09+0000"
  },
  {
     "name": "Tony Smith",
     "category": "Musician/band",
     "id": "456456456456",
     "created_time": "2012-02-22T06:56:18+0000"
  },
  {
     "name": "Stations",
     "category": "Company",
     "id": "567657567",
     "created_time": "2012-01-30T23:08:39+0000"
  }

]

}

and I then want to list e.g. all the names returned so:

foreach ($likesList->data as $element2){ 

    $name = $element2[name];

    echo $name; 

}

But it's empty?

foreach ($likesList['data'] as $element2){ 

     $name = $element2['name'];

     echo $name; 
}

After json_decode with parameter true you will have associative array. You can access to value by string key. Like in example above.

See this visualization of your data structure.

As you are receiving an array, you need $list["data"] and not $list->data. Also don't forget to quote the array key "name".