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

后端 未结 6 1868
挽巷
挽巷 2021-02-20 17:01

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[\         


        
相关标签:
6条回答
  • 2021-02-20 17:22

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

    if(strpos("1,2,3", $row['name']) !== false) && $Cond2) {
      doThis();
    }
    
    0 讨论(0)
  • 2021-02-20 17:30
    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

    0 讨论(0)
  • 2021-02-20 17:33
    if (in_array($name , array( 'Alice' , 'Bob' , 'Charlie')) && $condition2 ) {
     /* */
    } 
    
    0 讨论(0)
  • 2021-02-20 17:35

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

    0 讨论(0)
  • 2021-02-20 17:38

    You're lookin for the function in_array().

    if (in_array($row['name'], array(1, 2, 3)) && $cond2) {
        #...
    
    0 讨论(0)
  • 2021-02-20 17:39
    $name = $row['name'];
    if (($name == "1" || $name == "2" || $name == "3") && $cond2)
    {
      doThis();
    }
    
    0 讨论(0)
提交回复
热议问题