Over a million developers have joined DZone.

Loop In PHP Using For (Ascending)

DZone's Guide to

Loop In PHP Using For (Ascending)

· ·
Free Resource
If you have a set number of times you need to repeat a piece of coding, using the for loop is the easiest way to accomplish this.

$i is the starting number, 1 in this case. This loop will repeat itself until $i reaches 10 - you can change this to any desired number. The bit inbetween the { and } is simply what is repeated - replace this with anything you want. :)

for ($i = 1; $i <= 10; $i++) {
   echo $i;

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}