Search code examples
phpisset

Check for multiple null isset values


I am checking if two values are null. If both are null I want to return false, if either or both are not null, I want to return true.

My current code returns true only when both are not null but I want it to return true when either or not null.

// check if both null
   if (!isset($myarray['dataone'], $myarray['datatwo']))
       {
           echo 'false';
        );    
       } else {
           echo 'true';
        );
       }
       return $emptytabs;

Solution

  • For that you can use relational operators. AND (&&) OR (||)

    By using AND (&&) operators.

    if ( (!isset($myarray['dataone']) || (!isset$myarray['datatwo'] ))
    {
        echo 'false';  
    } 
    else 
    {
        echo 'true';
    }
    

    By using OR ( || ) operators.

    if (isset($myarray['dataone'] && isset$myarray['datatwo'])
    {
        echo 'false';  
    } 
    else 
    {
        echo 'true';
    }