PHP xor Keyword
Example
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 »
Definition and Usage
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.
Related Pages
Read more about operators in our PHP Operators Tutorial.
More Examples
Example
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 »
❮ PHP Keywords
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.