Consider:
echo 50 >> 4;
Output:
3
Why does it output 3?
As documented on php.org, the >>
operator is a bitwise shift operator which shifts bits to the right:
$a >> $b - Shift the bits of $a $b steps to the right (each step means "divide by two")
50 in binary is 110010
, and the >>
operator shifts those bits over 4 places in your example code. Although this happens in a single operation, you could think of it in multiple steps like this:
00011001
00001100
00000110
00000011
Since binary 11
is equal to 3
in decimal, the code outputs 3.