Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

how get end of array in foreach php

$last_key = end(array_keys($array));
foreach ($array as $key => $value) {
    if ($key == $last_key) {
        // last element
    } else {
        // not last element
    }
}
 
PREVIOUS NEXT
Tagged: #array #foreach #php
ADD COMMENT
Topic
Name
1+9 =