Why does the following statement return true?
"608E-4234" == "272E-3063"
I have also tried this with single quotes around the strings. The only way I can get it to evaulate to false is by using the === operator instead of ==
My guess is PHP is treating it as some sort of equation but it seems a bit of a strange one.
Can anybody elaborate?
"608E-4234"is the float number format, so they will cast into number when they compares.608E-4234and272E-3063will both befloat(0)because they are too small.For
==in php,http://php.net/manual/en/language.operators.comparison.php
Attention:
What about the behavior in javascript which also has both
==and===?The answer is the behavior is different from PHP. In javascript, if you compare two value with same type,
==is just same as===, so type cast won’t happen for compare with two same type values.In javascript:
So in javascript, when you know the type of the result, you could use
==instead of===to save one character.For example,
typeofoperator always returns a string, so you could just usetypeof foo == 'string'instead oftypeof foo === 'string'with no harm.