how to code a weather forecast? here is what I have:   $data['list'] [0] ['weather'] [0] ['description'],                     'icon' => $data['list'] [0] ['weather'] [0] ['icon'],                     'maxtemp' => $data['list'] [0] ['temp'] ['max'],                     'mintemp' => $data['list'] [0] ['temp'] ['min'],                     'humidity' => $data['list'] [0] ['humidity'],                     'speed' => $data['list'] [0] ['speed']                                      );                 return $weather;             }               // Check to see if the web FORM was submitted with a city.             if (FALSE) {                 // Call your function passing it the city and assign the result to the variable $forecast.                 if ($forecast) {                     echo ' /* @var $city type */                     ' . $city . ' Weather Forecast                                             ' . date("l g:i a", $currentTime) . '                         ' . date("jS F, Y", $currentTime) . '                         ' . ucwords($forecast['description']) . '                                                                                     High ' . $forecast['maxtemp'] . '°C                       Low ' . $forecast['mintemp'] . '°C                                                     Humidity: ' . $forecast['humidity'] . ' %                     Wind: ' . $forecast['speed'] . ' km/h                 ';                 }             } else {                 echo '                                         City:                                                         ';             }             ?>

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

how to code a weather forecast?

here is what I have:

 <?php
            //code
            $currentTime = time();
            

            // Create a function called getForecast that accepts a city as a parameter and returns an array with the
            // the weather description, icon, maxtemp, mintemp, humidity and wind speed.
            function foo () {
                $country = "US";
                $url = "http://api.openweathermap.org/data/2.5/forecast/daily?q=" . $city . "," . $country . "&units=metric&cnt=1&lang=en&appid=c0c4a4b4047b97ebc5948ac9c48c0559";
                $json = file_get_contents($url);
               // json_decode converts a JSON object into a PHP array.  You will need to use var_dump or print_r to view the structure of the data returned to build your $weather array
                $data = json_decode($json, true);
                $weather = array(
                    'description' => $data['list'] [0] ['weather'] [0] ['description'],
                    'icon' => $data['list'] [0] ['weather'] [0] ['icon'],
                    'maxtemp' => $data['list'] [0] ['temp'] ['max'],
                    'mintemp' => $data['list'] [0] ['temp'] ['min'],
                    'humidity' => $data['list'] [0] ['humidity'],
                    'speed' => $data['list'] [0] ['speed']
                    
                );
                return $weather;
            }

 

            // Check to see if the web FORM was submitted with a city.
            if (FALSE) {
                // Call your function passing it the city and assign the result to the variable $forecast.
                if ($forecast) {
                    echo '
/* @var $city type */
                    <h2>' . $city . ' Weather Forecast</h2>
                    <div class="time">
                        <div>' . date("l g:i a", $currentTime) . '</div>
                        <div>' . date("jS F, Y", $currentTime) . '</div>
                        <div>' . ucwords($forecast['description']) . '</div>
                    </div>
                    <div class="weather-forecast">
                        <img src="https://openweathermap.org/img/w/' . $forecast['icon'] . '.png" class="weather-icon" />
                    High ' . $forecast['maxtemp'] . '°C <span class="min-temperature"> 
                    Low ' . $forecast['mintemp'] . '°C</span>
                </div>
                <div class="time">
                    <div>Humidity: ' . $forecast['humidity'] . ' %</div>
                    <div>Wind: ' . $forecast['speed'] . ' km/h</div>
                </div>';
                }
            } else {
                echo '
                    <form method="POST" action="weatherforecast.php">
                    City: <input type="text" name="city"/><br/><br/>
                    <input type="submit" name="forecast" value="Get Forecast"/>
                    </form>
                ';
            }
            ?>

 

Weather Forecast (AssicX Forecast Weather using PHIX Forecast Weather using PH X ▸ (558) Weather app API X
C
Getting Started How To Java help Layout Design Theory ... Illustrator Special Effe...
Kansas City Weather
Wednesday 5:39 pm
19th April, 2023
Overcast Clouds
High 25.43°C Low 16.77°C
Humidity: 76 %
Wind: 10.12 km/h
Type here to search
cweb.northcentralus.cloudapp.azure.com/~philip/assignment5/weatherforecast.php
1
İ
C Create a function callecx
Reading Assignment: ...
CBS All Access Confir...
69°F
FavTutor - Live Coding X
www.myworkday.com
ចង
+
<
Best ASMR Microphon...
(4)
D
ENG
I
↓
5:44 PM
4/19/2023
X
»
4
Transcribed Image Text:Weather Forecast (AssicX Forecast Weather using PHIX Forecast Weather using PH X ▸ (558) Weather app API X C Getting Started How To Java help Layout Design Theory ... Illustrator Special Effe... Kansas City Weather Wednesday 5:39 pm 19th April, 2023 Overcast Clouds High 25.43°C Low 16.77°C Humidity: 76 % Wind: 10.12 km/h Type here to search cweb.northcentralus.cloudapp.azure.com/~philip/assignment5/weatherforecast.php 1 İ C Create a function callecx Reading Assignment: ... CBS All Access Confir... 69°F FavTutor - Live Coding X www.myworkday.com ចង + < Best ASMR Microphon... (4) D ENG I ↓ 5:44 PM 4/19/2023 X » 4
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Dictionary
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education