Forum Moderators: coopster

Message Too Old, No Replies

Using comparison Operators to compare more than 2 variables

         

w9914420

6:52 pm on Jul 7, 2012 (gmt 0)

10+ Year Member



Hi guys,

You will have to excuse my articulation in matters of PHP its all new and slightly confusing.

What I am trying to do is execute a line of code based on these variables having the same value.

e.g I Have this:


if (($first == 2) && ($second == 2)){
// do something
}


This I understand but how would I execute the code in a case where the values may range from 0-10 in both the $first and $second variable.

The only thing I can think of is creating an array for each value which is very laborious way of doing it.What I am trying to do is this:


if (($first == 2) && ($second == 2) && ($third == 2)){
// do something
}


but the solution needs to be flexible so that any 3 matching values ranging from 0-9 will execute the code.

thanks

w9914420

incrediBILL

9:08 pm on Jul 7, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you mean all three must have the same value?

If that's the case then do this:

if ( ($first == $second) && ($second == $third) ){
// do something
}


It'll only do something when all 3 match.

w9914420

10:15 am on Jul 15, 2012 (gmt 0)

10+ Year Member



Thank you, IncrediBILL

A most elegant solution to a mind-altering problem :)