Reputation: 3
VERY basic question: I currently have the following (array?) for a select box within a form but I need to change the jump/step in numbers that appear in the drop down. At the moment it is in multiples of 100
, from 300-1500
but I need multiples of 100 up to 1000 and then 1250 and 1500.
for($i = 300; $i <= 1500; $i += 100)
Upvotes: 0
Views: 181
Reputation: 6036
$step = 100;
for($i = 300; $i <= 1500; $i += $step){
if ($i >= 1000) {$step = 250}...
or
$inc = 100;
foreach (range(300, 1500, $inc) as $number)
{
echo "<Option>".$number."</Option>";
if ($number >= 1000){$inc = 250}
}
but i am not 100% sure if the second one works
Upvotes: 0
Reputation: 1
Just add the options from 100 to 1000 with a for loop and then add the other two options afterwards.
<select>
<?php
for($i = 100; $i <= 1000; $i+=100)
{
echo "<option>" . $i . "</option>";
}
?>
<option>1250</option>
<option>1500</option>
</select>
Upvotes: 0
Reputation: 713
Have you tried using the function range()
?
You can configure start, end, and step.
http://php.net/manual/en/function.range.php
Upvotes: 1