FOREACH WITH INDEX

PHOTO EMBED

Tue Oct 06 2020 21:25:15 GMT+0000 (UTC)

Saved by @sgp #php

foreach($array as $key => $element) {
    if ($key === array_key_first($array))
        echo 'FIRST ELEMENT!';

    if ($key === array_key_last($array))
        echo 'LAST ELEMENT!';
}
content_copyCOPY

https://stackoverflow.com/questions/1070244/how-to-determine-the-first-and-last-iteration-in-a-foreach-loop