Re: foreach fails on unitialized array?

From: Date: Thu, 29 Aug 2002 11:20:38 +0000
Subject: Re: foreach fails on unitialized array?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-114496@lists.php.net to get a copy of this message
>I would expect foreach to treat an unitialized variable as an empty >array and hence do nothing. Is this the expected behaviour? >if(is_array($myvar)) foreach($myvar as $key => $value ) { > ... >} other possibility, so that the foreach is run each time (and it doesn't affect the source code, you can put it wherever you want) : if(!is_array($myvar)) { $myvar = array(); } regards ! Eric

« previous php.general (#114496) next »