Why does PHP think the two strings are equal?
If ("03E-004611" = "36E-008026") echo 'Equality ';
Reply to discussion (solution)
This post was last edited by xuzuning at 17:10:29, January 8 ,.
var_dump("03E-004611"=="36E-008026"); //bool(true)var_dump(03E-004611, 36E-008026); //float(0) float(0)var_dump("03E-004611"==="36E-008026"); //bool(false)
A string composed of digits. it is converted to a numerical value before comparison.
Why does PHP think the two strings are equal?
If ("03E-004611" = "36E-008026") echo 'Equality ';
The upstairs explanation is not perfect, because you are using double quotation marks, and you are composed of digits, which can be executed in double quotation marks. this is a characteristic of php, if it is changed to single quotes, it will be different.
Because E is the 10 screen operation "03E-004611", it is infinitely close to 0 when it is converted to the number of points, 3 * pow (10,-4611), less than this high precision, so it's all 0.
Long knowledge
Why does PHP think the two strings are equal?
If ("03E-004611" = "36E-008026") echo 'Equality ';
The upstairs explanation is not perfect, because you are using double quotation marks, and you are composed of digits, which can be executed in double quotation marks. this is a characteristic of php, if it is changed to single quotes, it will be different.
The same is true for single quotes.
This has nothing to do with whether it is in a single double quotation mark!
Just a cognitive question about scientific notation
You said I have tried 90A-904611 and 36E-008026. These two strings are not equal.
Among them, 36E-008026 can be regarded as scientific notation, while 90A-904611 is not
Therefore, such numbers must be compared by strings instead of numerical values.
Rising posture