Tag Archives: PHP Triple Equal Operator

php-equals-operator

PHP Equal operator

PHP Equal operator

There are three equal operator or sign available in PHP.

php equals operator

  1. Assignment or single equal (=)
  2. Equality or double equal(==)
  3. Identical or triple equal(===)

Let us describe one by one with the help of the example.

PHP Single equal operator

Single equal operator is basically used for assigning the value to on the right to the variable on the left, as shown in the below example.

Syntax of PHP single equal operator

<?php

echo "Single Equal operator<br>";
$firstNumber=5;
$SecondNumber=10;
$sum=$firstNumber+$SecondNumber;
echo " Sum=$sum";

?>
Single Equal operator
Sum=15

Double equal operator

Double equal operator is used to checks the left and right value are equal, as shown in the example below.

Example of Double equal operator

<?php

echo "Double Equal operator<br>";
$a=5;
$b=10;
if($a==$b)
{
echo "Both are equal";	
}
else
{
echo "Both are not equal";	
}

?>

Output

Double Equal operator
Both are not equal

Triple equal operator

Triple equal operator is used to checks the left and right value are equal with same data type that means left value and right value must be in same data type.

Example of Triple equal operator

<?php

echo "Triple- Equal operator<br>";
$a=5;
$b=5.0;
if($a===$b)
{
echo "Both are equal";	
}
else
{
echo "Both are not equal";	
}

?>

Output

Triple- Equal operator
Both are not equal