kisukedeath

Foreach loop first - last iteration

Sep 17th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.18 KB | None | 0 0
  1. $i = 0;
  2. $len = count($array);
  3. foreach ($array as $item) {
  4.     if ($i == 0) {
  5.         // first
  6.     } else if ($i == $len - 1) {
  7.         // last
  8.     }
  9.     // …
  10.     $i++;
  11. }
Advertisement
Add Comment
Please, Sign In to add comment