=== Operator
The ‘===’ won’t do assignment either. It is used to compare both values and data types of two given operands. It is a more strict version of ‘==’ operator. This operator is used to check if the given values and their data types are equal or not. If both the values are equal, it returns true, otherwise it returns false.
Syntax:
operand1 === operand2
Example: Implementation to showcase the use of ‘===’ operator.
<?php
$a = 34;
$b = 34;
// When both have equal
// value and data type
if ($a == $b) {
echo "Equal";
} else {
echo "Not Equal";
}
echo "\n";
// When both have equal value
// but different data type
if ("34" === 34) {
echo "Equal";
} else {
echo "Not Equal";
}
?>
Output
Equal Not Equal
Difference between the (=), (==), and (===) operators in PHP
In PHP, the ‘=’ operator is used for assignment, while the ‘==’ operator is used for loose equality comparison, meaning it checks if two values are equal without considering their data types. On the other hand, the ‘===’ operator is used for strict equality comparison, meaning it checks if two values are equal and of the same data type.
Contact Us