Wednesday, June 10, 2026
HomeLanguagesHow do the PHP equality (== double equals) and identity (=== triple...

How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?

Equal Operator ==

The comparison operator called Equal Operator is the double equal sign “==”. This operator accepts two inputs to compare and returns true value if both of the values are same (It compares only value of variable, not data types) and return a false value if both of the values are not same. 
This should always be kept in mind that the present equality operator == is different from the assignment operator =. The assignment operator changes and assigns the variable on the left to have a new value as the variable on right, while the equal operator == tests for equality and returns true or false as per the comparison results.
Example: 
 

php




<?php
 
// Variable contains integer value
$x = 999;
 
// Variable contains string value
$y = '999';
 
// Compare $x and $y
if ($x == $y)
    echo 'Same content';
else
    echo 'Different content';
?>


Output: 

Same content

 

Identical Operator ===

The comparison operator called as the Identical operator is the triple equal sign “===”. This operator allows for a much stricter comparison between the given variables or values. 
This operator returns true if both variable contains same information and same data types otherwise return false.
Example: 
 

php




<?php
 
// Variable contains integer value
$x = 999;
 
// Variable contains string value
$y = '999';
 
// Compare $x and $y
if ($x === $y)
    echo 'Data type and value both are same';
else
    echo 'Data type or value are different';
?>


Output: 

Data type or value are different

 

In the above example, value of $x and $y are equal but data types are different so else part will execute.
 

RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6896 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS