Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Increment by Half

I have a quick question, which is probably easy to answer. I've goolged around, but not sure if I am searching correctly or what. Anyway, using PHP, how can I increment by halves?

For example, I know I can use the following loop:

<?php 
for ($i=1; $i<21; $i++) {
    print($i);
}

And it will print 1 - 20.

But, how can I get it to output something like the following:

1
1.5
2
2.5
etc...

Sorry for my ignorance on this, I'm just not sure how to go about it. Thanks!

like image 263
Dodinas Avatar asked Jan 27 '11 22:01

Dodinas


1 Answers

instead of $i++, use $i += .5

like image 175
JakeParis Avatar answered Oct 02 '22 18:10

JakeParis