Page 1 of 1

foreach

Posted: Sun Jul 04, 2004 4:59 pm
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

Posted: Sun Jul 04, 2004 5:01 pm
by markl999

Code: Select all

if(is_array($foo) && !empty($foo)){
    foreach($foo as $bar){
        ....
    }
}
?

Posted: Sun Jul 04, 2004 5:02 pm
by tim
i'll try it, i tried the empty() and a few of the array handlers.

i'll let ya know, thanks mark.