这里有一些我写的代码: (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
为什么当键是0时,if语句会返回true?此foreach循环处理逻辑,当键==0(和除了键为“van”之外的任何其他键)时应用逻辑,并且这会破坏逻辑,因为当键为0时它会返回true。
需要帮忙吗?
谢谢。
$vanSteps
上看到一个print_r
吗? - Phil