You can simply find the last array element with array length -1

$var = array("1","2","3","");
$i = 0;
$len = count($var);
foreach ($array as $item) {
    if ($i == 0) {
        // first result
    } else if ($i == $len - 1) {
        // last result
    } 
    // …
    $i++;
}

Leave a Reply

Your email address will not be published. Required fields are marked *