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 (Descending)

  • submit to reddit
        For those times you need to do a loop in PHP, but have the outcome be in descending order (ie, start at 10 and end at 1).

for($i=$totalcode; $i>0; $i--){



Snippets Manager replied on Mon, 2012/05/07 - 1:25pm

Oh, yes! Thanks for that - the less coding the better! :D

Snippets Manager replied on Mon, 2006/07/10 - 10:48am

if you dont mind ending at zero you can also do: $i=10; while ($i--) { echo $i; }