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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -