This might sound naive, but in PHP, is it possible modify the outcome of an expression with one boolean value?
for example:
if(expression)
//execute code
now, how can i do this?
if(!expression)
//execute code
with the control of another boolean?
like:
$bool = true;
if( ($bool? :!)expression ) // if($bool) => !expresion ; if(!$bool) => expression
//execute code
so basically i want to have the have !expression
when $bool
is true and expression
when $bool is false
i do know i can :
$bool ? !expression : expression
but it has the same expression twice...
if (expression == $bool)
or maybe
if (expression != $bool)
So basically you want to pass the test if $bool
is true or expression
is true, but not both. Textbook definition of XOR:
if( $bool xor expression)
// execute code
I'm not sure i understand you but you can store the result of the expression in variable:
<?php
$bool = false;
$result = (1 == 2 || 1 == 1);
if ($bool && !$result) {
//do stuff
echo '1';
} else if (!$bool && $result) {
//other stuff
echo '2';
} else {
echo '3';
}
?>
or maybe
$bool = false;
$result = (1 == 2 || 1 == 1);
$newVar = ($bool ? !$result : $result);
Or use eval but it's a little bit tricky.