0

I'm trying to understand what is being evaluated in the if statement contained within the for loop i.e what does '1&$i' expand to?

  for( $i= 0 ; $i <= 10 ; $i++ )
  {
         if(1&$i) {

          //do something
          }
  }
Barry Hamilton
  • 943
  • 3
  • 15
  • 35

1 Answers1

1

The if statement is basically saying "If $i is odd, then do something"

Jeff Lambert
  • 24,395
  • 4
  • 69
  • 96
  • `1 & [anything]` will only ever be true if the last bit in `[anything]` is set. If `[anything]` is a number, then `1 & [anything]` will only ever be true if that number is odd – Jeff Lambert Oct 15 '15 at 19:33