Answers for "foreach first item php"

PHP
1

php foreach first element

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

    if ($key === array_key_last($array))
        echo 'LAST ELEMENT!';
}
Posted by: Guest on July-02-2021

Browse Popular Code Answers by Language