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

2004-04-30 Thread BOOT
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



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

2004-04-30 Thread Gryffyn, Trevor
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:[EMAIL PROTECTED] 
 Sent: Friday, April 30, 2004 11:49 AM
 To: [EMAIL PROTECTED]
 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
 
 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2004-04-30 Thread Neil Freeman
Why not just use a switch?...

switch ($x) {
case $a:
case $b:
case $c:
case $d:
//do whatever you need
break;
default:
//catch any other values here
break;
}
Neil

BOOT wrote:
***
This Email Has Been Virus Swept
***
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!

--
--
 www.curvedvision.com
--
This communication is confidential to the intended recipient(s). If you are not that person you are not permitted to make use of the information and you are requested to notify the sender immediately of its receipt then destroy the copy in your possession. Any views or opinions expressed are those of the originator and may not represent those of Advanced System Architectures Ltd.

*** This Email Has Been Virus Checked ***

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php