alcool9999
08-28-2009, 02:27 PM
hi
i need to check if two variables are diffrent.
hopefully in the same way an if statment can check if two variables are the same with
if ($var1 == $var2);
can i just put an ! in front of one or something.
thanks
Fou-Lu
08-28-2009, 02:31 PM
I assume you mean the value of the variables?
if ($var1 != $var2) // Or the less used: $var1 <> $var2
Techincally you should probably be able to wrap the whole works with a !.
if (!($var1 == $var2))
That should also work, but doesn't really make a lot of sense to me.
SKDevelopment
08-28-2009, 02:32 PM
This would show if variables are different without type check:
if ($var1 != $var2)
I mean integer 5 and string "5" would be considered as equal.
This would show if variables are different with type check:
if ($var1 !== $var2)
In this case integer 5 and string "5" would be considered as not equal.
the-dream
08-28-2009, 02:32 PM
if($var1 != $var2) {
You only use a singe = rather with the ! than ==.
Fou-Lu
08-28-2009, 02:33 PM
if($var1 != $var2) {
You only use a singe = rather with the ! than ==.
No thats not correct. != is typeless, !== is typed, just like == is typeless and === is typed.
So 5 == '5' is true, but 5 === '5' is not.
tailender1
08-29-2009, 12:53 PM
i have been confused by this concept for long time.. thanks any way