Forum Moderators: coopster
if ($x = 1)
is *always* true becuase you are assigning 1 to $x so it is the equivalent of
if ( 1 )
if (2 == 2) - this is true
if (2 == "2") - this is true
if (0 == false) = this is true
if (2 == 3) - this is false
Sometimes you want to make sure you are testing that something matches type and value so
if (0 == false) = this is true
but
if (0 === false) = this is false
if (2 === "2") = this is also false
because although false evaluates to an integer value of zero, it is not an integer value of zero. It's a boolean false. When you use === instead of == it evaluates equivalency.
So
= is for assignment
== is for testing equality
=== is for testing equivalency
[edited by: ergophobe at 10:42 pm (utc) on Aug. 6, 2005]