I have the following code
$List2 = json_decode(file_get_contents("https://___URL____&format=json"),true);
the following works perfectly
echo '<pre>';print_r($List2);echo '</pre>';
and produces e.g.
Array
(
[0] => Array
(
[uid] => 123456
[name] => John Williams
[pic_square] => http://nc4/565228_799523_q.jpg
[birthday_date] => 07/31/1987
)
[1] => Array
(
[uid] => 123789
[name] => Jane Thompson
[pic_square] => http://profile.ak.fbcdn.net/785505233_1702140670_q.jpg
[birthday_date] => 07/31/1983
)
[2] => Array
(
[uid] => 456789
[name] => John Gaffney
[pic_square] => http://profet/hprofile-ak-snc4/3717297628_q.jpg
[birthday_date] => 07/31/1965
)
[3] => Array
(
[uid] => 987654
[name] => Johnny Illand
[pic_square] => http://c4/41766_14329_q.jpg
[birthday_date] => 07/31/1958
)
I want to run a foreach to print the result somewhat neater obviously, so i’m trying the following:
$data = $List2['data'] ;
foreach ($data as $nr => $friends){
echo $friends[name].' - ';
}
But I get
Warning: Invalid argument supplied for foreach()
I’m stumped and it’s probably something easy!
Try with: