Change language

What is the difference between PHP comparison operators (== double equals) and identity (=== triple equals)?

|
The comparison operator, called the equality operator, is a double equal sign "==". This operator takes two inputs for comparison and returns true if both values ​​are the same (it only compares the value of the variable, not data types) and returns false if both values ​​are not the same.Always remember that the existing equality operator == is different from the assignment operator =. The assignment operator modifies and assigns the variable on the left a new value as the variable on the right, and the equality operator == tests for equalityand returns true or false according to the comparison results.Example :  
// The variable contains an integer value $x = 999;  
// Vatiable contains a string $y = ’999’ ;  
// Compare $x and $y if ( $x == $y ) echo ’ Same content’ ; else echo ’ Different content’ ; ?>
Exit:
Same content 
Identical operator === The comparison operator, called the identical operator, is the triple equal sign "===". This operator allows you to significantly more stringently compare given variables or values.
This operator returns true if both variables contain the same information and data types, otherwise it returns falseExample :  
// The variable contains an integer value $x = 999;  
// Vatiable contains a string $y = ’999’ ;  
// Compare $x and $y if ( $x === $y ) echo ’ Data type and value both are same’ ; else echo ’ Data type or value are different’ ; ?>
Exit:
Data type or value are different
In the above example, the values ​​of $x and $y are equal, but the datatypes are different, so otherwise the part will execute.