相关疑难解决方法(0)

比较PHP中的多个值

我想离开这个:

if($var == 3 || $var == 4 || $var == 5 || $var =='string' || $var == '2010-05-16') {
   // execute code here
}
Run Code Online (Sandbox Code Playgroud)

对此:

if($var == (3, 4, 5, 'string', '2010-05-16')) { // execute code here }
Run Code Online (Sandbox Code Playgroud)

看起来非常冗余以便继续输入$var,我发现它使得阅读有点麻烦.PHP中有没有办法以这种方式简化它?我在这里阅读一篇文章,在使用XQuery时你可以使用=运算符$var = (1,2,3,4,5)等.

php conditional-operator

13
推荐指数
4
解决办法
3万
查看次数

标签 统计

conditional-operator ×1

php ×1