I have a json file (items.json) that looks like following:
{"response":{"success":1,"current_time":1446373851,"items":[
{
"Item1": {"last_updated":1446372015,"quantity":73,"value":1200},
"Item2": {"last_updated":1446372015,"quantity":40,"value":5297},
"Item3": {"last_updated":1446372015,"quantity":148,"value":2507}
}]}}
I've tried to create a for loop to create elements with values from each item in the json:
$values = file_get_contents( $siteurl.'/json/items.json');
$values = json_decode($values);
foreach ($values->items as $key => $value) {
if($value==Item1 && $value->value>1000){
<p><?php echo $value->value ; ?></p>
}
}
In the above example i'm testing the first value in "items" (Item1). I'd like to be able to have a foreach for all these three items.
But the browser outputs the following error "Warning: Invalid argument supplied for foreach() in".
How do I correctly create a foreach where I can get values from all "items" objects (ex "Item1" and "Item2) that works for my json file format.