Possible Duplicate:
Reference - What does this symbol mean in PHP?
What does adding a '&' mean in this snippet I found?
$i = 10;
if($i&1){
echo "$i is odd";
}
else {
echo "$i is even";
}
Possible Duplicate:
Reference - What does this symbol mean in PHP?
What does adding a '&' mean in this snippet I found?
$i = 10;
if($i&1){
echo "$i is odd";
}
else {
echo "$i is even";
}
It's the bitwise AND operator. in your case, it takes the binary representations of 10
and 1
and performs the logical AND operation on the individual bits.
That's a binray and. So for example 148 (binary 10010100) & 136 (binary 10001000) will be 128 (binary 10000000). So $i & 1 is either 1 (true) or 0 (false)