Question: I have an array of objects, any array in php.
How do i skip the last element in the foreach iteration?

Answer: 
Use a variable to track how many elements have been iterated so far and cut the loop when it reaches the end:

```
$count = count($array);

foreach ($array as $key => $val) {
    if (--$count <= 0) {
        break;
    }

    echo "$key = $val\n";
}

```

If you don't care about memory, you can iterate over a shortened copy of the array:

```
foreach (array_slice($array, 0, count($array) - 1) as $key => $val) {
    echo "$key = $val\n";
}

```
If you don't want to delete the last array entry with pop, you could skip it like this

```
$array = array('v1','v2','v3',...)

$counter = 1;

foreach($array as $value)
{
    //do your thing in loop

    if($counter == count($array)) continue; // this will skip to next iteration if last element encountered.
    $counter++;
}

```