tags:

views:

215

answers:

3

Say i start my counter at 400. How would i execute a foreach loop that will run backwards until 0?

pseudocode

$i = 400;
foreach(**SOMETHING**)){
//do stuff
$i--;
}
+9  A: 
for($i = 400; $i > 0; $i--)
{
  // do stuff
}

as curiosity:

$i = 400;
while($i > 0)
{
  // do stuff
  $i--;
}

or

$a = range(400, 1);

foreach($a as $i)
{
  // do stuff
}
Balon
lol, it must be the right answer!
John Conde
+2  A: 

how about a for loop

for($i = 400; $i > 0; $i--)
{
    //stuff
}
John Boker
A: 

foreach is used for iterating over sequences or iterators. If you need a conditional loop then use for or while.

Ignacio Vazquez-Abrams