Some pseudo code, I wanted to do this with Foreach if possible
I don't know if is possible to get the position from the array
$num = array ( 1 => 7,
2 => 9,
3 => 10,
4 => 11,);
foreach ($num as $value) {
if (first position) { echo $value . '<br> first <br>';}
elseif (middle position) { echo $value . '<br> middle <br>';}
elseif (last position) { echo $value . '<br> last';}
}
Expected result
7
first
9
middle
10
middle
11
last
$key => $value
then you could with the full array and figure out where you are. php.net/manual/en/control-structures.foreach.phpThe second form will additionally assign the current element's key to the $key variable on each iteration.