What you are trying to do will defeat the purpose of foreach loop. It is meant to loop through the entire array and make our job easy.
for ex: You can get the array size using COUNT function in php and then can use for loop and set the limit to arraysize-2, so the last array will be omitted