Difference between or and xor


My question is operator related. Today I studied about the operators. Having a confusion. In PHP what is the difference between "or" and "xor". I know both of them are related to Boolean expression. But can't find the original difference.

Anyone please help to understand it more clearly.


Answers:


It has to do with mutual exclusion. xor is exclusive. or is inclusive.

Truth Table Comparison

$x $y ($x or $y) ($x xor $y)
0  0    0          0
1  0    1          1
0  1    1          1
1  1    1          0

Note: the difference in the last case. xor is only true when either $x or $y is true, but not both (as the case for or).