Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Counting in fives when producing list

Tags:

php

Given that:

$min=30
$max=60

(min and max being variables that are rounded either to the nearest 5 or 10)

How do you generate an output that counts in five within the min and max range in a table format?

For example with the above example you would get an output of:

cname  |
-------|
30     |
-------|
35     |
-------|
40     |
-------|
45     |
-------|
50     |
-------|
55     |
-------|
60     |
-------|
like image 669
methuselah Avatar asked Dec 12 '25 01:12

methuselah


2 Answers

Minor variant on the above answers

foreach(range($min,$max,5) as $value) {
    //  do whatever
}
like image 79
Mark Baker Avatar answered Dec 14 '25 15:12

Mark Baker


for ($i = 30; $i <= 50; $i+=5) {
    echo $i;
}

For more information have a look here: http://php.net/manual/en/control-structures.for.php

like image 26
tonymarschall Avatar answered Dec 14 '25 15:12

tonymarschall