ver*_*ric 20 php variables comparison shorthand
基本上我想知道是否有办法缩短这样的东西:
if ($variable == "one" || $variable == "two" || $variable == "three")
Run Code Online (Sandbox Code Playgroud)
以这种方式,可以对变量进行测试,或者与多个值进行比较,而不必每次都重复变量和运算符.
例如,某些内容可能会有所帮助:
if ($variable == "one" or "two" or "three")
Run Code Online (Sandbox Code Playgroud)
或任何导致打字减少的事情.
Joh*_*nde 36
in_array() 是我用的
if (in_array($variable, array('one','two','three'))) {
Run Code Online (Sandbox Code Playgroud)