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--;
}
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--;
}
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
}
foreach
is used for iterating over sequences or iterators. If you need a conditional loop then use for
or while
.