Lampwrights Forum > Linux, Apache, MySQL, PHP > PHP
Register Community Today's Posts Search

Reply
 
Thread Tools
07-22-2010, 04:50 PM   #1
EightyEight
Junior Member
 
Join Date: Jul 2010
Posts: 1
Rep Power: 0
EightyEight is getting browny points
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?
EightyEight is offline   Reply With Quote

07-22-2010, 04:54 PM   #2
Jeff
Administrator
 
Jeff's Avatar
 
Join Date: Jul 2010
Posts: 402
Rep Power: 10
Jeff is getting browny points
Quote:
Originally Posted by EightyEight View Post
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
Jeff is offline   Reply With Quote
Reply

Tags

troubleshooting php



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -4. The time now is 09:10 AM.


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