【发布时间】:2011-08-26 13:18:48
【问题描述】:
这是我的一些代码:(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(以及任何其他 key,除非 key 是 'van')时应用的逻辑,这会弄乱逻辑,因为它在 key 为 0 时返回 true。
有什么帮助吗?
谢谢。
【问题讨论】:
-
是的,我们可以在
$vanSteps上看到 print_r 吗?