Page 1 of 1

[SOLVED] Multiple conditions in an IF statement.

Posted: Thu Aug 30, 2007 3:47 am
by impulse()
Hi.

I was hoping the following code would work:

Code: Select all

$a = 1; $b = 1; $c = 1; $d = 1;

if ($a == $b == $c == $d)
  echo "THey all equal 1";
But it throws out a parse error. Is there a shorter way to write this, rather than:

Code: Select all

if ($a == $b && $b == $c && $c == $d)
Regards,

Posted: Thu Aug 30, 2007 4:05 am
by onion2k
I'm not sure it's really a good idea, but...

Code: Select all

if ($a+$b+$c+$d==4) {

Posted: Thu Aug 30, 2007 4:30 am
by stereofrog

Code: Select all

if(max($a, $b, $c, $d) == min($a, $b, $c, $d))
if(array_unique(array($a, $b, $c, $d)) == array($a))
if(array($a, $b, $c, $d) == array_fill(0, 4, $a))
I'd go with simple comparison, though.

Posted: Thu Aug 30, 2007 4:53 am
by Kieran Huggins
so essentially, no.

Posted: Thu Aug 30, 2007 9:44 am
by impulse()
I'll stick with the simple comparison then.

Thanks for the help.