Hi,
I think the top element of a stack is called "Head", but maybe wrong.
And $topElement = $stack[count($stack)-1]; sound good.
However, when you push, it returns the new number of elements in the array. So you can do this too:
$stack = array();
$topPos=array_push($stack, ...);
$topElement = $stack[$topPos];
Or you can use end($stack). (end() )
See you