Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php get first last loop

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

    if ($key === array_key_last($array)) {
        echo 'LAST ELEMENT!';
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #php #loop
ADD COMMENT
Topic
Name
4+6 =