Possible Duplicate:
How do the equality (== double equals) and identity (=== triple equals) comparison operators differ?
Why this
var_dump(0 == "string");
outputs this
bool(true)
Isn't the context of ==
operator supposed to convert 0
into FALSE
and "string"
into TRUE
according to this set of rules?
var_dump(0 == "string");
is doing a numeric (integer) comparison
0 is an integer, so "string" is converted to an integer to do the comparison, and equates to an integer value of 0, so 0 == 0 is true
Se the comparison with various types table in the PHP documentation for details
The table shown here is more fit for your case.
It shows TRUE
for comparing 0
with "php"
.
Within the comparison you do not convert both operands to a boolean, but one operand will be converted to match the type of the other operand. In your case the string gets converted to an integer, which results in another 0
. This gives you 0 == 0
, which yields true.
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