RE: [PHP] Would like to do if ($a in (1, 2, 3, 4)) or something

From: Date: Mon, 16 Oct 2000 16:42:13 +0000
Subject: RE: [PHP] Would like to do if ($a in (1, 2, 3, 4)) or something
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-20389@lists.php.net to get a copy of this message
> -----Original Message----- > From: Matt Waggoner [mailto:mattw@getacard.com] > Sent: Saturday, October 14, 2000 1:17 PM > To: php-general@lists.php.net > Subject: [PHP] Would like to do if ($a in (1, 2, 3, 4)) or something > > > In SQL, you can do things like: > > ...where field1 in (1, 2, 3, 4) > > does PHP have an equivalent? The only thing I can think of, a bit of a > hack, is: > > if (in_array($a, array(1, 2, 3, 4))) { > > but that seems a little kludgey for something like this. Is > there a simpler way? It's not any less kludgy, I suppose, and it's a little longer, but another equivalent would be: switch ($a) { case 1: case 2: case 3: case 4: do_stuff(); break; } --- Mark Roedel | "Blessed is he who has learned to laugh Systems Programmer | at himself, for he shall never cease LeTourneau University | to be entertained." Longview, Texas, USA | -- John Powell

« previous php.general (#20389) next »