Search code examples
phpvariablesboolean-operations

compare 3 variables to define another on PHP


I have been trying to find some information, without success, about this:

I have 3 variables that might, or not, have a value on it. I would like to check all 3 and if any one has the value I want to create another variable with its own value.

something like this:

if (var1 OR var2 OR var3 == 'yes'){var4='anothervalue';};

I have no idea what is the symbol for the condition 'OR'.


Solution

  • if(in_array('yes', array($var1, $var2, $var3)) {
        $var4 = 'anothervalue';
    }
    

    Another way to do this would be:

    if($var1 == 'yes' || $var2 == 'yes' || $var3 == 'yes') {
        $var4 = 'anothervalue';
    }