请帮忙。
for($i=0; $i<12; $i++ ){
switch($i) {
case 0:
case 1:
case 2:
case 3:
case 4:
echo ("i is less than 5 <br>");
break;
case 5:
case 6:
case 7:
case 8:
case 9:
echo ("i is less than 10 <br>");
break;
default:
echo ("i is 10 or more <br>");
}
}
这是我在 Java 书中得到的示例代码,我将上面的代码翻译成 PHP。
以下代码的输出:
i is less than 5
i is less than 5
i is less than 5
i is less than 5
i is less than 5
i is less than 10
i is less than 10
i is less than 10
i is less than 10
i is less than 10
i is 10 or more
i is 10 or more
我的问题是,即使案例 0 到案例 3 没有任何以下代码并且案例 4 是带有 echo 语句的案例,它怎么会输出“i 小于 5”?我很困惑,谁能给我解释一下。提前致谢。