Menu

#6 Warning: Invalid argument supplied for foreach()

open
nobody
None
5
2009-09-30
2009-09-30
No

When pulling single data fields out, the script works great, but when I tried to run the supplied sample to get the forecast I got this error:

Warning: Invalid argument supplied for foreach() in /home/dad/public_html/weather/pxweather.class.php on line 121

My PHP version (5.2.11)

The is the code I used:

<?php

require_once("pxweather.class.php");
$w = new Weather($city = "Kahului");
$w->load();

foreach($w->getForecasts() as $forecast)
{
echo "FORECAST FOR " . $forecast['day']. ":\n";
echo $w->weatherString($forecast['weather']) . "\n";

if (isset($forecast['low_temp']))
echo "Low temperature: " . $forecast['low_temp'] . "\n";

if (isset($forecast['high_temp']))
echo "High temperature: " . $forecast['high_temp'] . "\n";

echo "Description: " . $forecast['text'] . "\n\n";

}

?>

Any ideas?

Discussion


Log in to post a comment.

MongoDB Logo MongoDB