Interviews3 answers
Difference between == and === operator in php. ?
3 Answers
Vijay KumarPosted Feb 25, 2018, 8:33 AM EST
In PHP == is equal operator and returns TRUE if $a is equal to $b after type juggling and === is Identical operator and return TRUE if $a is equal to $b, and they are of the same data type.
Example Usages:
<?php
$a=true ;
$b=1;
// Below condition returns true and prints a and b are equal
if($a==$b){
echo "a and b are equal";
}else{
echo "a and b are not equal";
}
//Below condition returns false and prints a and b are not equal because $a and $b are of different data types.
if($a===$b){
echo "a and b are equal";
}else{
echo "a and b are not equal";
}
?>
source : https://www.onlineinterviewquestions.com/core-php-interview-questions/
Vijay KumarPosted Feb 25, 2018, 8:32 AM EST
The == operator just checks to see if the left and right values are equal. But, the === operator (note the extra “=”) actually checks to see if the left and right values are equal, and also checks to see if they are of the same variable type (like whether they are both booleans, ints, etc.).
saurabh singhPosted Mar 18, 2015, 2:07 AM EDT


