How does this code block works?
Posted
by
Justin John
on Stack Overflow
See other posts from Stack Overflow
or by Justin John
Published on 2012-12-15T04:50:37Z
Indexed on
2012/12/15
5:03 UTC
Read the original article
Hit count: 113
I can't understand how the following code works.
$start = 1;
while($start<10){
if ($start&1) {
echo "ODD ".$start." <br/> ";
}
else {
echo "EVEN ".$start." <br/> ";
}
$start++;
}
The $start&1
will return ODD and EVEN seperately.
Output
ODD 1
EVEN 2
ODD 3
EVEN 4
ODD 5
EVEN 6
ODD 7
EVEN 8
ODD 9
If we give $start&2
instead of $start&1
, it returns with another order.
How &1
&2
etc... works here?
© Stack Overflow or respective owner