php - easiest way to establish that a foreach loop is in it's final iteration -
possible duplicate:
how determine first , last iteration in foreach loop?
what best way establish foreach loop in it's final loop, , perform different functions accordingly?
the way approach increment variable , test variable against size of array (count()
):
$i = 0; $c = count($array); foreach($array $key => $value) { $i++; if ($i == $c) { // last iteration } else { // stuff } }
this may, obviously, not efficient method, though.
Comments
Post a Comment