PHP xor returns wrong value
问题 Using php 7.1.0 I'm running this little test: <?php $a = true; $b = true; $value = $a xor $b; if ($value == true) { print "bad!\n"; } else { print "good\n"; } and it's coming back and saying bad. Why? An xor of two true values should be FALSE, not true. 回答1: The problem is operator precedence. The xor operator has lower precedence than = , so your statement is equivalent to: ($value = $a) xor $b; You need to write: $value = ($a xor $b); or $value = $a ^ $b; The ^ operator is bit-wise XOR, not