Side effects of PHP string = = Comparison

Source: Internet
Author: User

$a = ' 212345678912000005 ';

$b = ' 212345678912000001 ';

Var_dump ($a = = $b);

The output of this code is bool (true), which means that the judgment will conclude that the two are equal. Similar attributes are false or not set in the 3rd argument of the In_array () function. The reason is to first judge whether a string is a number and then convert it to a long or double (C language data type) to be judged again – using ZENDI_SMART_STRCMP. However, the comments in the source code say that the declaration takes into account the overflow situation,

else if (Dval1 = = Dval2 &&!zend_finite (dval1)) {

/* Both values overflowed and have the same sign,

* So a numeric comparison would to be inaccurate * *

Goto string_cmp;

}

The Dval1 and Dval2 are two strings converted to the double type value respectively. But why is that still the case? Perhaps this is not the correct judgment. Further study to say ...

Workaround, using three equal sign "= =" instead of two equals "=", the In_array () function sets the third argument to True:in_array (' Val ', $array, true).



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.