Never been to DZone Snippets before?

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

Loop in PHP Using For (Descending) (See related posts)

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).

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

 echo"$i";
}

Comments on this post

notme posts on Jul 10, 2006 at 11:56
if you dont mind ending at zero you can also do:

$i=10;
while ($i--) {
echo $i;
}
nothingless posts on Aug 26, 2006 at 17:00
Oh, yes! Thanks for that - the less coding the better! :D

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts