for ($i=0; $i < 6; $i++) { echo $i; } 

Displays 1,2,3,4,5,6 . And how to display only even 2,4,6 ?

  • I hope the next question will not be "But how to display only the odd ones?"? - 0-Level UNIX Monk
  • The question is, get odd and here get same even, what is it like? You already decide what you need. - And

1 answer 1

Or implement a parity check inside the loop:

 if ($i%2 == 0) echo $i; 

either do a loop with step 2

 for($i=0; $i<=6; $i+=2){ 

obviously, the second is preferable.