PHP

Examples of difference between == and == in PHP1 min read

What’s the difference between double and triple equals in PHP? PHP supports both double (==) and triple (===) comparison. Then when to use double equal to and when to use triple equal to in our code.

When I first saw the comparison using triple equal to it seems confusing in the beginning but later I understood why triple equality operator is used.

Difference Between Double and Triple Equals in PHP




Double equals is also known as type-converting equality. When we use double equal to in our code, it first converts the operands to the same type before comparing the values.
Let’s understand this through example –

Triple Equals (===) in PHP

Triple equals (strict comparison) compares both values as well as the data type. So let’s check what’s the output of the above script when we use triple equals.

Important Points –

PHP is a loosely typed language. Using the double equal operator allows for a loose checking of a variable.

Now let’s compare the same value with triple equal to.

To avoid such cases in your code try to use triple equals(===).

Leave a Comment