PHP switch 语句中 case 后的分号有效吗?
我正在为客户端调试一些代码,发现以下语法:
switch ($i) {
case 0;
echo "i equals 0";
break;
case 1;
echo "i equals 1";
break;
case 2;
echo "i equals 2";
break;
}
case 语句以分号而不是冒号结尾。事实证明这确实可以编译,但它合法吗?我以前从未见过这种语法。
I'm debugging some code for a client and found the following syntax:
switch ($i) {
case 0;
echo "i equals 0";
break;
case 1;
echo "i equals 1";
break;
case 2;
echo "i equals 2";
break;
}
The case statements end in semi-colons rather than colons. Turns out this does compile, but is it legit? I've never seen that syntax before.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自文档:
From the documentation:
正如您可以在这里检查的那样,它有效: http://codepad.org/hOLQP98D 我认为它有效,因为它下降了通过
As you can check here, it works: http://codepad.org/hOLQP98D i think it works because it falls through
是的,只要
$i
具有数字值Yup, just as long as
$i
has a number value