Why does in_array() wrongly return true with these (large numeric) strings?

后端 未结 9 2137
夕颜
夕颜 2020-12-08 00:35

I am not getting what is wrong with this code. It\'s returning \"Found\", which it should not.

$lead = \"418176000000069007\";
$diff = array(\"41817600000006         


        
9条回答
  •  -上瘾入骨i
    2020-12-08 01:12

    If the third parameter strict is set to TRUE then the in_array() function will also check the types of the needle in the haystack, and because the limit is beyond the maximum integer value.

    So if PHP encounters a number beyond the bounds of the integer type, it will be interpreted as a float instead. Also, an operation which results in a number beyond the bounds of the integer type will return a float instead. Check the PHP manuals.

    if (in_array($lead,$diff,true))
    

提交回复
热议问题