RE: [PHP] Control structure - easier way than repeating conditions in IF?

From: Date: Fri, 30 Apr 2004 15:50:24 +0000
Subject: RE: [PHP] Control structure - easier way than repeating conditions in IF?
Groups: php.general 
Request: Send a blank email to php-general+get-185052@lists.php.net to get a copy of this message
You could do something like this: $valuesarr = array($a,$b,$c,$d); If (in_array($x,$valuesarr)) { # do something } Or I guess even: If (in_array($x,array($a,$b,$c,$d))) { # do something } I don't know if your method or this method have better performance but it's a little easier to read I guess. -TG > -----Original Message----- > From: BOOT [mailto:pfine@of-law.com] > Sent: Friday, April 30, 2004 11:49 AM > To: php-general@lists.php.net > Subject: [PHP] Control structure - easier way than repeating > conditions in IF? > > > Hello! > > Can anyone tell me if there is an easier/shorthand for: > > if ( ($x == $a) || ($x == $b) || ($x == $c) || ($x == $d) > ....... ) {;} > > > I understand the logic of why the following does not work: > > if ($x == ($a || $b || $c || $d)) {;} > > > > > Thanks! > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#185052) next »