foreach ($likes as $like) {
// Extract the pieces of info we need from the requests above
$id = idx($like, 'id');
$item = idx($like, 'name');
fwrite($fileout,json_encode($like));
fwrite($fileout,PHP_EOL );
}
$json_string = file_get_contents('testson.json');
$get_json_values=json_decode($json_string,true);
foreach ($get_json_values as $getlikes) { ?>
<li>
<a href="https://www.facebook.com/<?php echo $getlikes['id']; ?>" target="_top">
</li>
<?php
}
When opening the browser, there is a Warning: Invalid argument supplied for foreach(). I don't understand why would my arguments be invalid.
If I add the if, nothing happens, which shows what the actual problem is. But the question is WHAT IS THE PROPER WAY TO DO THIS? I'm pretty sure it's very simple, but i've been struggling with this for more than an hour. My json files has fields like this, so I don't think there would be the problem:
{"category":"Musician\/band","name":"Yann Tiersen (official)","id":"18359161762"}
Please help me, I really got tired with it, and I don't know what to do. So... how can I decode the file into an array?
foreach()works equally well on objects as on arrays - if he's getting anInvalid argument supplied...error, then he's passing something else (probably boolean false).$getlikes['id']