This is the bitwise-AND operator. Remember that on a computer, every integer is stored in binary form, and the binary digit with the least significance is 2 ^ 0 == 1. So, every odd number will have a lower binary digit = 1.
So, the bitwise AND operator compares your bit value with constant 1 . Bits that are 1 in both operands are set to 1 as a result, but bits that are 0 in both operands are set to 0 as a result. The end result (which will be either 1 or 0 ) is forced to boolean due to PHP because you use it as a clause in the if() .
There is a very good reason to check for uniformity with & instead of % : Speed! The % operator requires a division operation, so the remainder can be calculated, which is computationally large, much more expensive than just comparing the bits directly.
Example:
$num = 9; // 9 == 8 + 1 == 2^3 + 2^0 == 1001b echo (string)($num & 1); // 1001b & 0001b = 0001b - prints '1' $num = 10; // 10 == 8 + 2 == 2^3 + 2^1 == 1010b echo (string)($num & 1); // 1010b & 0001b = 0000b - prints '0'
source share