I am doing something wrong but I cannot figure it out.
I have this JSON
$data = {
"data":[
{
"app_min_temp":15.5,
"valid_date":"2018-08-10",
"weather":{
"icon":"c02d",
"code":801,
"description":"Few clouds"
},
"max_temp":26.3,
"datetime":"2018-08-11"
},
{
"app_min_temp":18.5,
"valid_date":"2018-08-11",
"weather":{
"icon":"c02d",
"code":801,
"description":"Few clouds"
},
"max_temp":26.3,
"datetime":"2018-08-11"
}
],
"city_name":"Berlin"
};
Expected Result And trying to get the values from app_min_temp and valid_date and print them all together. Something like
app_min_temp:15.5 valid_date: 2018-08-10 Weather description: Few clouds
app_min_temp:18.5 valid_date: 2018-08-11 Weather description: Few clouds
FOREACH I am trying to foreach trougn the json like this
$json = json_decode($data);
foreach($json as $data) {
echo "app_min_temp: ".$data[0]->app_min_temp.PHP_EOL."valid_date: ".$data[0]->valid_date.PHP_EOL."Weather description: ".$data[0]->weather->description.PHP_EOL; //etc
}
The Results But I am getting strange result with only the first set of data printed. Like:
app_min_temp: 15.5
valid_date: 2018-08-10
Weather description: Few clouds
app_min_temp:
valid_date:
Weather description:
app_min_temp:
valid_date:
Weather description:
app_min_temp:
valid_date:
Weather description:
app_min_temp:
valid_date:
Weather description:
app_min_temp:
valid_date:
Weather description:
app_min_temp:
valid_date:
Weather description:
Thanks