Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
$key = "523df554f4e883874873853b897b6da0";
$lat = "43.8029100";
$lon = "131.9457800";
$url = "https://api.openweathermap.org/data/2.5/forecast?lat=$lat&lon=$lon&appid=$key&units=metric";
$data = file_get_contents($url);
$json = json_decode($data, true);
foreach($json["list"] as $v){
//print_r($v);exit();
// выводим температуру
$temp[] = $v["main"]["temp"];
// выводим дату
$date[] = $v["dt"];
$date[] = date("d.m.Y",$v["dt"]);
// print_r("date - ".$date."\n");
$min = $v["main"]["temp_min"];
$max = $v["main"]["temp_max"];
echo $min." ".$max."\n";
$ss = array_sum($temp);
$minmax[] = abs($max)-($min);
//print_r ("different - ".$minmax."\n");
}
exit();
//выводим среднее арифметическое
$t = end($date);
$f = array_shift($date);
$f = date("d.m.Y",$f);
print_r ("start - ".$f."\n");
print_r ("end - ".$t."\n");
//выводим среднее арифметическое
$d = count($temp);
$s = array_sum($temp);
$o = $s/$d;
print_r ("average - ".round($o, 1)."\n");
$dd = count($minmax);
$ss = array_sum($minmax);
$oo = $ss/$dd;
print_r ("average - ".round($oo, 1)."\n");