这是我遇到问题的代码 - 简单的foreach迭代数组.有时来自数组的元素可以具有键"mailto" - 在这种情况下它应该执行一些任务.但由于某种原因,带有"0"键的第一个元素也进入"mailto"情况.
<?php
foreach (
array(
" this shouldnt appear, it's without mailto as key - 1",
" this shouldnt appear, it's without mailto as key - 2",
"mailto" => " this should appear ",
" this shouldnt appear, it's without mailto as key - 3",
) as $type => $text
) {
echo "#$type#\n";
switch ($type) {
case "mailto":
echo ">$type< $text\n";
break;
default:
break;
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
#0#
>0< this shouldnt appear, it's without mailto …Run Code Online (Sandbox Code Playgroud)