Over a million developers have joined DZone.

Loop In PHP Using For (Ascending)

·
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;
}
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}