[SOLVED] Multiple conditions in an IF statement.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

[SOLVED] Multiple conditions in an IF statement.

Post 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,
Last edited by impulse() on Thu Aug 30, 2007 9:44 am, edited 1 time in total.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

I'm not sure it's really a good idea, but...

Code: Select all

if ($a+$b+$c+$d==4) {
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post 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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

so essentially, no.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

I'll stick with the simple comparison then.

Thanks for the help.
Post Reply