<?php $city = "Marunouchi"; $API_KEY = "not watch"; $BASE_URL = "http://api.openweathermap.org/data/2.5/forecast/?q=".$city.",jp&appid=" . $API_KEY . ""; $forecast = json_decode(file_get_contents($BASE_URL), true); echo $city . "<br>"; $list = $forecast["list"]; echo $list[0]["dt_txt"] . "<br>"; echo $list[0]["weather"][0]["main"] . "<br>"; echo $list[0]["weather"][0]["description"] . "<br>"; $temp = $list[0]["main"]["temp"]; echo "気温 : " . ($temp - 273.15) . "°<br>"; echo "湿度 : " . $list[0]["main"]["humidity"] . "%<br>"; echo "雲 : " . $list[0]["clouds"]["all"] . "%<br>"; echo "風速 : " . $list[0]["wind"]["speed"] . "m<br>"; ?>
foreachに書き換えます。
echo "<b>" . $city . "</b><br>"; $list = $forecast["list"]; foreach($list as $value){ echo $value["dt_txt"] . "<br>"; echo $value["weather"][0]["main"] . "<br>"; echo $value["weather"][0]["description"] . "<br>"; $temp = $value["main"]["temp"]; echo "気温 : " . ($temp - 273.15) . "°<br>"; echo "湿度 : " . $value["main"]["humidity"] . "%<br>"; echo "雲 : " . $value["clouds"]["all"] . "%<br>"; echo "風速 : " . $value["wind"]["speed"] . "m<br><br>"; }
うわーでたー