Forum Moderators: coopster

Message Too Old, No Replies

What does == comparison operator mean?

== comparison operator

         

matthewamzn

7:23 pm on Aug 6, 2005 (gmt 0)

10+ Year Member



I know what these operators stand for:
=,<,>,<=,>=,!=

But I'm not sure what this one means:
==

Can someone tell me?

DanA

7:53 pm on Aug 6, 2005 (gmt 0)

10+ Year Member



= sets a value
== means equal within a condition

ergophobe

8:24 pm on Aug 6, 2005 (gmt 0)

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



Here's how it works

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]

matthewamzn

8:46 pm on Aug 6, 2005 (gmt 0)

10+ Year Member



Thanks