我可以使用逻辑“或"吗?在 PHP switch 语句的情况下? [英] Can I use a logical "or" in a PHP switch statement case?
本文介绍了我可以使用逻辑“或"吗?在 PHP switch 语句的情况下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 switch case 中使用or"或and"?这就是我所追求的:
Is it possible to use "or" or "and" in a switch case? Here's what I'm after:
case 4 || 5:
echo "Hilo";
break;
推荐答案
不,但你可以这样做:
case 4:
case 5:
echo "Hilo";
break;
请参阅 PHP 手册.
关于 AND 情况:switch 只检查一个变量,所以这不起作用,在这种情况下你可以这样做:
About the AND case: switch only checks one variable, so this won't work, in this case you can do this:
switch ($a) {
case 4:
if ($b == 5) {
echo "Hilo";
}
break;
// Other cases here
}
这篇关于我可以使用逻辑“或"吗?在 PHP switch 语句的情况下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文