DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Loop In PHP Using For (Ascending)

06.20.2006
| 5908 views |
  • submit to reddit
        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;
}