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

Member

by braeden , in category: Technology , 4 years ago

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

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by adolf , 4 years ago

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<?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 Threads:

What is difference Between PHP 5 and 7?
What is difference between session and cookie in PHP ?
How to Create a Composer Package in 2025?
What is difference between Method overriding and overloading in PHP?
What is a null coalescing operator in PHP7?
What Are the Best Practices for Optimizing Performance in Vue.js Applications?