在 PHP switch 语句中有效的大小写后的分号? [英] Semi-colon after a case valid in a PHP switch statement?
本文介绍了在 PHP switch 语句中有效的大小写后的分号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为客户端调试一些代码并发现以下语法:
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;
}
case 语句以分号而不是冒号结尾.事实证明这确实可以编译,但它合法吗?我以前从未见过这种语法.
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.
推荐答案
来自 文档:
可以在以下情况后使用分号代替冒号:
It's possible to use a semicolon instead of a colon after a case like:
switch($beer)
{
case 'tuborg';
case 'carlsberg';
case 'heineken';
echo 'Good choice';
break;
default;
echo 'Please make a new selection...';
break;
}
这篇关于在 PHP switch 语句中有效的大小写后的分号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文