php - Getting "Warning: Invalid argument supplied for foreach()" when I have two foreach -


i have following code:

if ($login->messages || $content->messages) {     echo '<div id="message">';     foreach ($login->messages $message) {         echo $message;     } foreach ($content->messages $message) {         echo $message;     }     echo '</div>'; } 

where both $login->messages , $content->messages arrays may empty. when $login->messages empty $content->messages not, things work fine , messages in $content->messages displayed however, when $login->messages has , $content->messages empty, login messages shown, error "warning: invalid argument supplied foreach() in" under messages. don't see i'm doing wrong.

thank you.

either $login->messages or $content->messages not array. may think empty array - false, null, '', or 0.

i check them var_dump() see type.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -