这是我的一些代码:(p 只是回显并添加换行符)
foreach ($vanSteps as $k => $reqInfo)
{
p($k);
if ('van' == $k) { p('The key is the van, continue'); continue; }//continue if we reached the part of the array where van is key
//do stuff
}
我得到这个输出:
0
The key is the van, continue
1
2
3
van
The key is the van, continue
为什么当key为0时if语句返回true?这个 foreach 循环处理当 key == 0(以及任何其他键,除非键是“van”)时应用的逻辑,这会扰乱逻辑,因为当 key 为 0 时它返回 true。
有什么帮助吗?
谢谢。
Use ===
对于这个比较。当 PHP 比较字符串和整数时,它首先将字符串转换为整数值,然后进行比较。
See 比较运算符 http://php.net/manual/en/language.operators.comparison.php在手册中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)