PHP的in_array意外结果 [英] PHP's in_array unexpected result

查看:96
本文介绍了PHP的in_array意外结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行这段PHP小代码时:

When I execute this small piece of PHP code:

php -r "echo(in_array(0, array('aaa', 'bbb')));"

这呼应 true ...

如果我将严格标志添加到 in_array 中,我当然有很好的返回值,但是我只是不明白为什么它返回(我不能!)。
如果有人能解释我,我今晚会睡个好觉。

Of course I have the good return value if I add the strict flag to in_array, but I just can't understand why it returns true (I can't !!). If anyone can explain me I will sleep well tonight.

PS:对不起,这只是出于好奇...

PS: Sorry that this is just about curiosity...

推荐答案

这是因为对于 PHP ,此代码将返回 true

That's because for PHP this code will return true

0 == 'aaa'

因此,无需严格检查 PHP 即可在给定数组中找到您的值。

So without strict checking PHP will find your value in given array.

这篇关于PHP的in_array意外结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆