这是一个可能的功能吗?
我需要检查一个变量是否存在于我需要检查的列表中,并且 cond2 是否为真,例如
if($row['name'] == ("1" || "2" || "3") && $Cond2){
doThis();
}
它对我不起作用,我在复制粘贴中所做的只是我的列表和变量名
这是一个可能的功能吗?
我需要检查一个变量是否存在于我需要检查的列表中,并且 cond2 是否为真,例如
if($row['name'] == ("1" || "2" || "3") && $Cond2){
doThis();
}
它对我不起作用,我在复制粘贴中所做的只是我的列表和变量名
if(in_array($row['name'], array('1', '2', '3')) && $Cond2) {
doThis();
}
PHP 的in_array()
文档:http ://us.php.net/manual/en/function.in-array.php
您正在寻找功能in_array()
。
if (in_array($row['name'], array(1, 2, 3)) && $cond2) {
#...
if (in_array($name , array( 'Alice' , 'Bob' , 'Charlie')) && $condition2 ) {
/* */
}
使用 in_array 函数 if(in_array($row['name'], array(1,2,3)) && $cond2){ do ... }
$name = $row['name'];
if (($name == "1" || $name == "2" || $name == "3") && $cond2)
{
doThis();
}
我有比这更简单的东西,如果它仍然可能的话......
if(strpos("1,2,3", $row['name']) !== false) && $Cond2) {
doThis();
}