Output a message only if just one of the expressions is true:
<?php
if(5 < 3 xor 5 < 10) {
echo "Only one of the expressions was true";
}
?>
Try it Yourself »
The xor
keyword is a logical operator.
Logical operators are used to combine conditional statements.
The return value will only be true
if one of the statements is true
and the other one is false
.
Note: This operator has lower precedence than the assignment operator, which may lead to confusing results. Wrap the expression in parentheses to avoid unexpected results.
Read more about operators in our PHP Operators Tutorial.
Show the difference in precedence:
<?php
$result1 = true xor true;
echo "true xor true = ";
echo $result1 ? "true" : "false";
echo "<br>";
$result2 = (true xor true);
echo "(true xor true) = ";
echo $result2 ? "true" : "false";
?>
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!