这是我的一些代码:(p只是echos plus添加换行符)
- 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
当键为0时,为什么if语句返回true?这个foreach循环处理当key == 0时应用的逻辑(以及任何其他键,除非键是’van’),这会混淆逻辑,因为当key为0时它返回true.
有帮助吗?
谢谢.
使用===进行比较.当PHP比较字符串和整数时,它首先将字符串转换为整数值,然后进行比较.
请参见手册中的Comparison Operators.