这是我的一些代码:(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
}
Run Code Online (Sandbox Code Playgroud)
我得到了这个输出:
0
The key is the van, continue
1
2
3
van
The key is the van, continue
Run Code Online (Sandbox Code Playgroud)
当键为0时,为什么if语句返回true?这个foreach循环处理当key == 0时应用的逻辑(以及任何其他键,除非键是'van'),这会混淆逻辑,因为当key为0时它返回true.
有帮助吗?
谢谢.