PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?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"]; $ss = array_sum($temp); $minmax[] = $max-$min; //print_r ("different - ".$minmax."\n"); } //выводим среднее арифметическое $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");
Show:  
Copy Clear