CKTIS / PHP
Exclusive disjunction (xor)
Exclusive disjunction returns true exactly when one operand is truthy.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
($first xor $second)Exclusive disjunction returns true exactly when one operand is truthy. Two true alternatives cancel and produce false. PHP evaluates both sides, so both can have side effects. Use parentheses when storing the result because assignment has higher precedence.
($first xor $second)
[true,false,false]
Examples
<?php
$single = (true xor false);
$both = (true xor true);
$none = (false xor false);
echo json_encode([$single,$both,$none]);
Result
[true,false,false]