IN php, how do the following operands work?
^
|
e.g. $a = 11;
$b = 7;
echo $a ^ $b;
outputs 12
and
$a = 11;
$b = 7;
echo $a | $b;
outputs 15
Im not sure why in each case. Can someone please shed some light?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Those are bitwise XOR and OR.
With XOR each bit that is different in
$aand$bbecomes a1, the bits that are the same become a0.With OR each bit that is a
1in either$aor$bbecomes a1, in this case all the bits.There is also an AND equivalent:
$a & $b: // 0011 = 3A full list of PHP’s bitwise operators.