为什么in_array()错误地使用这些(大数字)的字符串返回true? [英] Why does in_array() wrongly return true with these (large numeric) strings?
问题描述
我没有得到什么是错的这个code。它返回发现,它不应该的。
$铅=418176000000069007;
$差异=阵列(418176000000069003,418176000000057001);如果(in_array($铅,$差异))
回声找到;
其他
回声未找到;
这是因为该号码存储在 PHP的局限性
,这是一个错误并纠正,并在 PHP
的更新版本解决了。的
该值超过 PHP_INT_MAX
。
尝试回声
/ 的print_r
$带领
和 $差异
不使用引号。这将导致
$领先---> 418176000000070000
$差异--->阵列([0] => 418176000000070000 [1] => 418176000000060000)
所以在这种情况下, in_array
结果是真的!
所以使用严
比较 in_array()
在 in_array设置第三个参数( )
为真正
如果(in_array($铅,$差异,真实))//利用类型太
回声找到;
其他
回声未找到;
?>
试试这个。它将工作。
I am not getting what is wrong with this code. It's returning "Found", which it should not.
$lead = "418176000000069007";
$diff = array("418176000000069003","418176000000057001");
if (in_array($lead,$diff))
echo "Found";
else
echo "Not found";
It is because of the limitations of the number storage in PHP
,this was a bug and is rectified and solved in newer versions of PHP
.
The values exceed PHP_INT_MAX
.
Try to echo
/print_r
$lead
and $diff
without using the quotes. It will result
$lead ---> 418176000000070000
$diff ---> Array ( [0] => 418176000000070000 [1] => 418176000000060000 )
so in this case the in_array
result is true!
so use strict
comparison in in_array()
by setting third argument in in_array()
as true
if(in_array($lead,$diff,true)) //use type too
echo "Found";
else
echo "Not found";
?>
Try this. It will work.
这篇关于为什么in_array()错误地使用这些(大数字)的字符串返回true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!