Present in both answers;Present only in the new answer;Present only in the old answer;
You could use couner: <?php $i = 0; $len = count($array); foreach ($array as $item) { if ($i == 0) { // first } else if ($i == $len - 1) { // last } // … $i++; } ?>
You could use a counter: $i = 0; $len = count($array); foreach ($array as $item) { if ($i == 0) { // first } else if ($i == $len - 1) { // last } // … $i++; }
Present in both answers;Present only in the new answer;Present only in the old answer;