Lampwrights Forum

Lampwrights Forum (http://www.lampwrights.com/index.php)
-   PHP (http://www.lampwrights.com/forumdisplay.php?f=4)
-   -   how to suppress foreach error? (http://www.lampwrights.com/showthread.php?t=17)

EightyEight 07-22-2010 04:50 PM

how to suppress foreach error?
 
I am trying to keep some code from popping out a foreach error if the array does not exist? I keep getting this error:

Code:

Warning: Invalid argument supplied for foreach()
Help?

Jeff 07-22-2010 04:54 PM

Quote:

Originally Posted by EightyEight (Post 19)
I am trying to keep some code from popping out a foreach error if the array does not exist?

Ok, there are a few ways.. Ideally you should declare the variable an array before you use it for anything:

Code:

$arr = array();
But if for whatever reason you cannot do that then:

Code:

if (is_array($arr))
{

###  Foreach



All times are GMT -4. The time now is 08:02 PM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2024, vBulletin Solutions, Inc.