foreach

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

foreach

Post by tim »

is there anyway to see if a foreach statement has no vars.

I am trying to avoid this:
Warning: Invalid argument supplied for foreach() in /home/theory/yada on line 59

I want to create a warning, like "There were no items selected" but my attempted have been for the no good.

kudos
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Code: Select all

if(is_array($foo) && !empty($foo)){
    foreach($foo as $bar){
        ....
    }
}
?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

i'll try it, i tried the empty() and a few of the array handlers.

i'll let ya know, thanks mark.
Post Reply