Home > Enterprise >  Populate Option Value
Populate Option Value

Time:10-18

I am looking for a way to populate an option value.

<?php for ($i = 1; $i <= 300; $i  ) : ?>
    <option value="<?php echo $i; ?>">1.<?php  print $i; ?> AVAX</option>
<?php endfor; ?>

I want for the above code to work something like this. 1.00 - 1.99 after reaching 1.99 I want it to navigate to 2.00 - 2.99 and so forth and onward until the numbers run out. How can I achieve that? The above result returns only 1.300

CodePudding user response:

You can set the increment to whatever you want

<?php for ($i = 1; $i <= 300; $i =0.01) : ?>
    <option value="<?php echo number_format($i, 2, '.', ''); ?>"><?php  echo number_format($i, 2, '.', ''); ?> AVAX</option>
<?php endfor; ?>   

demo

CodePudding user response:

What do you mean by until numbers run out? You do realize that numbers are infinite. Therefore, I can only assume that you want the options to have the series: 1.01, 1.02.... 1.99, 2.00, 2.01, 2.02, .... until 10.00.

If 10 is not the highest number you want to reach, then you can change the end limit of $i in the following code:

<?php
for ($i = 1; $i <= 10; $i  ) { 
   for ($j = 0; $j <= 99; $j  ) { 

         $num = "$i." . sprintf('d',$j);   // 1.01, 1.02, ...

         echo '<option value="' . $num . '">AVAX</option>';
        
   }
}
?>
         
    

  •  Tags:  
  • php
  • Related