PHP开关“||"工作不正常 [英] PHP switch "||" not working properly
本文介绍了PHP开关“||"工作不正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在switch语句中,当我有一个带有||"的情况时它不能正常工作.
In the switch statement, when i have a case with "||" it doesn't work properly.
$get = 'item';
switch ($get):
case 'items' || 'several-items':
echo 'items';
break;
case 'item':
echo 'item';
break;
endswitch;
此代码输出items
.这是一个 php 错误吗?
$get = 'several';
也输出 items
.
所以问题肯定出在'||'运算符,因为以下代码运行正常:
So the problem is definitely with the '||' operator, because the following code works just fine:
$get = 'item';
switch ($get):
case 'items':
case 'several-items':
echo 'items';
break;
case 'item':
echo 'item';
break;
endswitch;
推荐答案
不能使用 OR (||
) 和 AND (&&
) 运算符在 switch 语句中
You can't use OR (||
) and AND (&&
) operators in a switch statement
这篇关于PHP开关“||"工作不正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文