-1
People need to get data from a JSON file (I’m not the fuck in business). This api below is to display temperature via JSON + PHP, remembering that on the site of the same I can not get the maximum, minimum or display days of the week, but these data are in JSON, but how I will display them ?
<?php
/*
* Obtendo dados do HG Weather API
*
* Consulte nossa documentacao em http://hgbrasil.com/weather
* Contato: [email protected]
* Copyright 2015 - Hugo Demiglio - @hugodemiglio
*
*/
$cid = 'BRXX0198'; // CID da sua cidade, encontre a sua em http://hgbrasil.com/weather
$dados = json_decode(file_get_contents('http://api.hgbrasil.com/weather/?cid='.$cid.'&format=json'), true);
// Recebe os dados da API
?>
Below I’ll leave how I can display the other values.
<?php echo $dados['results']['city_name']; ?>
<?php echo $dados['results']['temp']; ?>
Below you can see the formatted JSON file to better understand and also its link Online
https://api.hgbrasil.com/weather/? format=json&cid=BRXX0198
{
"by":"cid",
"valid_key":false,
"results":{
"temp":23,
"date":"12/04/2017",
"time":"09:11",
"condition_code":"32",
"description":"Ensolarado",
"currently":"dia",
"cid":"",
"city":"Ribeirao Preto,",
"img_id":"32",
"humidity":"76",
"wind_speedy":"11.27 km/h",
"sunrise":"6:22 am",
"sunset":"6:2 pm",
"condition_slug":"clear_day",
"city_name":"Ribeirao Preto",
"forecast":[
{
"date":"12/04",
"weekday":"Qua",
"max":"28",
"min":"20",
"description":"Tempestades",
"condition":"storm"
},
{
"date":"13/04",
"weekday":"Qui",
"max":"28",
"min":"18",
"description":"Parcialmente nublado",
"condition":"cloudly_day"
},
{
"date":"14/04",
"weekday":"Sex",
"max":"29",
"min":"18",
"description":"Tempestades isoladas",
"condition":"storm"
},
{
"date":"15/04",
"weekday":"Sáb",
"max":"30",
"min":"18",
"description":"Ensolarado com muitas nuvens",
"condition":"cloudly_day"
},
{
"date":"16/04",
"weekday":"Dom",
"max":"30",
"min":"18",
"description":"Parcialmente nublado",
"condition":"cloudly_day"
},
{
"date":"17/04",
"weekday":"Seg",
"max":"26",
"min":"18",
"description":"Tempestades isoladas",
"condition":"storm"
},
{
"date":"18/04",
"weekday":"Ter",
"max":"28",
"min":"19",
"description":"Tempo nublado",
"condition":"cloud"
},
{
"date":"19/04",
"weekday":"Qua",
"max":"27",
"min":"20",
"description":"Tempestades",
"condition":"storm"
},
{
"date":"20/04",
"weekday":"Qui",
"max":"21",
"min":"19",
"description":"Tempestades isoladas",
"condition":"storm"
},
{
"date":"21/04",
"weekday":"Sex",
"max":"22",
"min":"16",
"description":"Tempestades isoladas",
"condition":"storm"
}
]
},
"execution_time":0.0,
"from_cache":true
}
I do not understand very well what you want. You want to display in your php the day of the week, min temp and max?
– Jessika
Exact would like to take the minimum, maximum and the day of the week. I don’t know much of JSON, like tried in the following ways.

<?php echo $dados['results']['max']; ?>
<?php echo $dados['results']['forecast']['max']; ?>
<?php echo $dados['forecast']['max']; ?>

– PoneiMlditoUM
No json
{
means object and[
array, then to access this information you will have to go through the forecast array. Example:<?php echo $dados['results']['forecast'][0]['max']; ?>
<?php echo $dados['results']['forecast'][0]['min']; ?>
<?php echo $dados['results']['forecast'][0]['weekday']; ?>
– Jessika
I did a test going through the array and really returned me the data of it very straight ! Thank you so helped a lot.
– PoneiMlditoUM