Search code examples
phplogical-operatorsstrstr

combine two if conditions results in one if condition


if condition 1 :

if(isset($_POST['searchOrder']) && $_POST['searchOrder']!='')
   {
       $userToSearch = "WHERE name='Conformed'"; 

   }

If condition 2 :

if(strstr($status, "value1") !== false ) 

    {
    $hide .= 'style="display: none;"';
    }

i need if condition 1 OR If condition 2 , i tried below :

if (((strstr($status, "value1") !== false) ||  
   isset($_POST['searchOrder']) && $_POST['searchOrder']!='')
   {
       $userToSearch = "WHERE name='Conformed'";        
   })
                  {
                     $hide .= 'style="display: none;"';              
                  }

I also tried below , but both gave error....

if ((strstr($status, "value1") !== false) ||  isset($_POST['searchOrder']) && $_POST['searchOrder']!=''))
                  {
                     $userToSearch = "WHERE name='Conformed'";   
                     $hide .= 'style="display: none;"';              
                  }

Solution

  • && has higher precedence than ||, so you might want to rearrange your conditions, or put parentheses around the second group. Then just write the second part in the same block, like this.

    if (strstr($status, "value1") !== false || (isset($_POST['searchOrder']) && $_POST['searchOrder']!=''))
    {
        $userToSearch = "WHERE name='Conformed'";
        $hide .= 'style="display: none;"';       
    }