Possible Duplicate:
The 3 different equals
Is there any difference between == and === in php? both seem to work fine for me when i use them in a conditional statement. I am very new to programming in PHP. Please consider this and answer in simple words.
== Operator: This operator is used to check the given values are equal or not. If yes, it returns true, otherwise it returns false. === Operator: This operator is used to check the given values and its data type are equal or not. If yes, then it returns true, otherwise it returns false.
Double Equals ( == ) checks for value equality only. It inherently does type coercion. This means that before checking the values, it converts the types of the variables to match each other. On the other hand, Triple Equals ( === ) does not perform type coercion.
The main difference between the == and === operator in javascript is that the == operator does the type conversion of the operands before comparison, whereas the === operator compares the values as well as the data types of the operands.
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 ==.
$a == $b
Equal true: if $a
is equal to
$b
, after type juggling.
$a === $b
Identical true: if $a
is equal to $b
, and they are of the same type.
$a === $b
TRUE
if $a
is equal
to $b
, and they are of the same type. (introduced in PHP 4
)
$a == $b
TRUE
if $a
is equal to $b
after type juggling.
Read here for more: http://www.php.net/manual/en/language.operators.comparison.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With