PHP == or ===

July 29th, 2008

Many PHP developers get confused when using the comparison operators.  Mainly weather to us two equal signs or three.  It really is a simple concept when you understand what it does.  The double equal sign (==) compares two data types which don’t have to be in the same type.  So for example you can compare

$a = 1

$b = ‘1′

$a is a integer and $b is a string. That would return true under a double equal sign.

However, the triple equal sign (===) the data types must be the same on both sides of the operand.  So… the above would return false since $a is a integer and $b is a string.

So just remember that double doesn’t matter on data types triple must be the same data type.


Leave a Reply