note 48561 deleted from control-structures.foreach by nlopess

From: Date: Wed, 29 Dec 2004 18:50:11 +0000
Subject: note 48561 deleted from control-structures.foreach by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-82466@lists.php.net to get a copy of this message
Note Submitter: aj at nospam dot com ---- One of the bits of code I find myself using over and over and over is something like this: if (is_array($array)){ foreach ($array as $index => $value){ // do stuff } } else { // do other stuff because it isn't an array } I use this a lot when I write a class to handle arrays and/or variables. If there is a simpler solution I would like to know what it is. If not, I have a suggestion the awesome php dev team might be interested in: foreach ($array as $index => $value){ // do stuff } else { // do other stuff because it isn't an array } How I envision this working is that the else statement runs if $array isn't really an array, but without the else statement you would get the same error you do now.

« previous php.notes (#82466) next »