Skip to main content
Jan 06, 2017

If you've just started to learn PHP, I'm sure that you've asked yourself what is difference between "==" (or equal operator) and "===" (or identical) operators.

Both of them are comparison operators in PHP programming language but it purpose is slightly different. Comparison operators, as their name implies, allow you to compare two values.

If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically. The type conversion does not take place when the comparison is === or !== as this involves comparing the type as well as the value.

In short, "==" (equal) should be used to check if the values of the two operands are equal or not. On the other hand, "===" (identical) checks the values as well as the type of operands.

Remember:

Equal operator: $x == $y (TRUE if $x is equal to $y after type juggling)

Identical operator: $x === $y (TRUE if $x is equal to $y, and they are of the same type)