The Comparison Operator == (Equality operator) and === (Identity Operator) are used to compare two values. They are also known as the loosely equal (==) operator and the strict identical (===) operator.
|==||Euality||$a == $b||TRUE if $a is equal to $b after type juggling|
|===||Identity||$a === $b||TRUE if $a is equal to $b, and both are of the same type|
PHP Operators: There are lots of operators in PHP but == and === operator performs similar kind of task strictly or casually.
- If operands are of different type then == and === will produce different results.The speed of the operators will be different in this case as == will perform type conversion and then do the comparison.
- If operands are of same type then both == and === will produce same results. The speed of both operators is almost identical in this case as no type conversion is performed by any of the operators.
Equality operator == converts the data type temporarily to see if its value is equal to the other operand, whereas === (the identity operator) doesn’t need to do any type casting and thus less work is done, which makes it faster than ==.
bool(true) bool(true) bool(true) bool(true) bool(false) bool(false) bool(false) bool(false) In first case
bool(true) bool(true) bool(false) bool(false)
Note: The === operator performs a ‘typesafe comparison’, it will only return true only if both operands have the same type and value whereas if only value is to be compared == is used.
- Why are elementwise additions much faster in separate loops than in a combined loop?
- Which will be faster while(1) or while(2)?
- Why Linux Hosting is Cheaper than Windows Hosting ?
- Why does password boxes are smaller than text boxes in IE ?
- Why to check both isset() and !empty() function in PHP ?
- Why require_once() function is so bad to use in PHP ?
- Why PHP script does not create a directory with 777 permissions ?
- Why does PHP 5.2+ disallow abstract static class methods ?
- Why use Guzzle Instead of cURL in PHP ?
- What is PHP and Why we use it ?
- Why is Parse Server the future of Backend As A Service?
- Why does sizeof(x++) not increment x in C?
- Why import star in Python is a bad idea
- Why You Should Choose React Native?
- What is the best way to include CSS file? Why use @import?
- Why Node.js ?
- Why overriding both the global new operator and the class-specific operator is not ambiguous?
- Why is Java 'write once and run anywhere'?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.