Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Getting foreach() error

Links for php scripts

Moderators: macek, egami, gesf

Getting foreach() error

Postby sheril » Thu May 02, 2013 11:03 pm

Warning: Invalid argument supplied for foreach()
function cs_take_location()
{
list ($location, ) = explode(".",getenv("HTTP_HOST"));

$locations = cs_get_locations(false);

foreach ($locations['citynames'] as $cityname=>$city)
{
if ($cityname == $location)
{
global $xcityid;
return $city[0];
}
}

foreach ($locations['countrynames'] as $countryname=>$countryid)
{
if ($countryname == $location)
{
return -$countryid;
}
}
}
pls help me to solve this problem
sheril
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu May 02, 2013 11:02 pm

Re: Getting foreach() error

Postby sandeep605085 » Fri May 03, 2013 12:39 am

Hi,

foreach always takes array.
http://php.net/manual/en/control-structures.foreach.php

I think $locations['citynames'] and $locations['countrynames'] are not array that's why its giving the error as Invalid argument supplied for foreach().

If you can post the $locations content and the function cs_get_locations. then it will be easy to solve what should be the exact parameter.

Thanks,
Sandeep Agrawal
Mindfire Solutions
User avatar
sandeep605085
New php-forum User
New php-forum User
 
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron