Simple PHP Condition help: if($Var1 = in list($List) and $Cond2) - Is this posslbe?

天大地大妈咪最大 提交于 2019-12-22 03:52:36

问题


Is this a possible function?

I need to check if a variable is existent in a list of ones I need to check against and also that cond2 is true eg

if($row['name'] == ("1" || "2" || "3") && $Cond2){
    doThis();
}

It's not working for me and all I changed in the copy paste was my list and the variable names


回答1:


if(in_array($row['name'], array('1', '2', '3')) && $Cond2) {
  doThis();
}

PHP's in_array() docs: http://us.php.net/manual/en/function.in-array.php




回答2:


You're lookin for the function in_array().

if (in_array($row['name'], array(1, 2, 3)) && $cond2) {
    #...



回答3:


if (in_array($name , array( 'Alice' , 'Bob' , 'Charlie')) && $condition2 ) {
 /* */
} 



回答4:


use in_array function if(in_array($row['name'], array(1,2,3)) && $cond2){ do ... }




回答5:


$name = $row['name'];
if (($name == "1" || $name == "2" || $name == "3") && $cond2)
{
  doThis();
}



回答6:


I have something simpler than that, if it's still possible...

if(strpos("1,2,3", $row['name']) !== false) && $Cond2) {
  doThis();
}


来源:https://stackoverflow.com/questions/910987/simple-php-condition-help-ifvar1-in-listlist-and-cond2-is-this-possl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!