if (($var != 0) && ($var != 1) && ($var != 2)) {
//...
}
Run Code Online (Sandbox Code Playgroud)
要么...
if (!in_array($var, array(0, 1, 2))) { /* ... */ }
Run Code Online (Sandbox Code Playgroud)
参见逻辑运算符.
最直截了当的方式:
if ($x != 0 && $x != 1 && $x != 2)
{
// take action!
}
Run Code Online (Sandbox Code Playgroud)
如果您知道您的变量是int,那么您也可以这样做:
if ($x < 0 || $x > 2)
{
// take action!
}
Run Code Online (Sandbox Code Playgroud)