Search code examples
phploopsdecimal

Making a simple for loop with decimals


for ($x = 0.01; 
$x <= 0.99; 
$x++) {?>

<option value="<?php echo $x;?>"><?php echo $x;?></option>
   <?php
  } ?>

This does not work.

I am trying to get a decimal loop from .01 to .99 The amount of time I have spent on this I could have just typed it out manually :)


Solution

  • You just have to change this:

    $x++  //Increments the value by 1
    

    to this:

    $x = $x + 0.01 //Increments the value by 0.01