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){
// выводим температуру
$temp[] = $v["main"]["temp"];
// выводим дату
$date[] = $v["dt"];
$date[] = date("d.m.Y H:i:s",$v["dt"]);
// print_r("date - ".$date."\n");
}
//выводим среднее арифметическое
$t = end($date);
$f = current($date);
print_r ("start - ".$f."\n");
print_r ("end - ".$t."\n");
//выводим среднее арифметическое
$d = count($temp);
$s = array_sum($temp);
print_r ("average - ".$s/$d);