问题
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