Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php $lat = "43.8029100"; $lon = "131.9457800"; $key = "523df554f4e883874873853b897b6da0"; $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); #print_r($json); foreach($json['list'] as $v){ $cb1[] = $v['main']['temp']; $cb3 = $v['main']['temp']; $cb0_1= $v['dt']; $cb0_1 = date("H:i y-m-d",$v['dt']); # echo("Temperature: ".$cb3." °C "."Date: ".$cb0_1.".\n" ); # $cb4[] = $v['main']['temp_min']; $cb4 = $v['main']['temp_min']; # $cb5[] = $v['main']['temp_max']; $cb5 = $v['main']['temp_max']; $cb0_1 = date("y-m-d",$v['dt']); $cb3_1[] = $cb0_1; }; #$nw = array_diff($cb6, $cb7); #echo $nw; $sum = array_sum($cb1); $cou = count($cb1); $cb2 = $sum / $cou; echo ("Average temperature: ".round($cb2, 1)."\n") ; echo ("First date: ".$cb3_1[0]."\n"); echo end($cb3_1);
Copy Clear