good evening. ingore all other elements, I want get first image in each foreach. how to?
$data = json_decode($json,true);
foreach ($data['data'][0] as $image) {
echo '<img src="'.$image['images'][0]['source'][0].'" />';
}
json tree is to开发者_如何学Co large, over the letters paste limit.
Oops! Your question couldn't be submitted because:
body is limited to 30000 characters; you entered 68494
so here is the url u can get the json tree https://graph.facebook.com/5550296508/photos
and u can paste in http://jsonlint.com/ look the struction well. Thanx.
With json_decode
every {}
(object) will become an object(stdClass)
and every []
(array) will become an array
. So:
$data->data[0]->images[0]->source
is what you need, to reach the first image source.
Edit: since the second parameter of json_decode
is true
, it will become an associative array, and it will be like:
$data['data'][0]['images'][0]['source']
To get all the images:
$images = array();
foreach ($data['data'] as $d)
{
foreach ($d['images'] as $i)
{
$images[] = $i['source'];
}
}
精彩评论