What is the difference between == and === operator in PHP ?

Sharad Jaiswal
Sharad Jaiswal

Posted On: Mar 24, 2020

 

In PHP == is an 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"; } ?>

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    PHP Interview Questions

    What is T_PAAMAYIM_NEKUDOTAYIM in PHP?

    T_PAAMAYIM_NEKUDOTAYIM is scope resolution operator used as :: (double colon) .Basically, it used to call static methods/variables of a Class...

    PHP Interview Questions

    What is session in PHP. How to remove data from a session?

    What is session in PHP. How to remove data from a session?..