note 37266 added to function.in-array

From: Date: Fri, 07 Nov 2003 20:36:13 +0000
Subject: note 37266 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-60119@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37266 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37266&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37266&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#60119) next »