note 37266 deleted from function.in-array by felipe

From: Date: Sun, 30 Dec 2007 18:52:07 +0000
Subject: note 37266 deleted from function.in-array by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134469@lists.php.net to get a copy of this message
Note Submitter: Lee Benson ---- If you're trying to compare a variable against several possible other variables, like this... if ($var == 1 || $var == 2 || $var == 3 || $var == 4) { // do this } You can make your code a lot neater by doing this: if (in_array($var,array(1,2,3,4))) { // do this } This way, you're not repeating the "$var == x ||" part of your expression over and over again. If you've used MySQL's IN() function for searching on multiple values, you'll probably appreciate using this code in your PHP scripts. Hope this helps a few people.

« previous php.notes (#134469) next »