In PHP programming, Many times we have seen and used different operators of PHP. This article demonstrate the difference between the operators which looks identical but used for different operations. In PHP we have three types of equal sign (=) operators, The description of each type is given below :
1. = : "=" stands for assignment operator. This operator is used for assigning values to variables.
Example :
<?php
$var = 'Test';
?>
2. == : "==" stands for equality operator. This operator used to check the value of operands are equal or not.
Example :
<?php
$x = '7';
$y = 7;
if($x == $y)
{
echo "Equal";
}
else
{
echo "Not Equal";
}
?>
Output : Equal
3. '===' : "===" stands for identical operator. This operator checks the values as well as the type of operands are same or not.
<?php
$x='7';
$y=7
if($x === $y){
echo "Equal";
}else{
echo "Not Equal";
}
echo "<br-->";
if($x === string($y)){
echo "Equal";
}else{
echo "Not Equal";
}
?>
Output :
Not Equal
Equal
Note : '==(equal)' operator performs typecasting automatically to compare values of operand while '===(identical)' operator performs typesafe comparison.
0 Comment(s)