Hi Guys,
I have just started learning PHP in the last few days so please be gentle!
When using the mathematical operator ^ (exponentiation), I seem to be getting unexpected output. I always thought (if my maths serves me correctly) that zero to the power something is always zero. Here is a looping piece of test code I am having trouble with:
$c = 0;
$tmp = 0;
for ($i=0;$i<12;$i++) {
$tmp = $c;
$c = $c ^ $i;
echo $tmp . ' ^ ' . $i . ' = ' . $c . '<BR>';
}
This produces the following output:
0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 2 = 3
3 ^ 3 = 0
0 ^ 4 = 4
4 ^ 5 = 1
1 ^ 6 = 7
7 ^ 7 = 0
0 ^ 8 = 8
8 ^ 9 = 1
1 ^ 10 = 11
11 ^ 11 = 0
Can anyone please tell me:
1. How this mathematical operator (^) works.
2. Why the output is not what I expected.
3. How do you evaluate exponents in PHP to give the correct output.
Many, thanks in advance.




