The Stack::peek()
function in PHP is used to get the reference of the element at the top of a stack.
Figure 1 shows the visual representation of the Stack::peek()
function.
stack_name->peek()
## where the stack_name is the name of the stack
This function does not require a parameter.
This function returns the element
that is available at the top of the stack.
It does not remove that element from the stack.
<?php$stack = new \Ds\Stack();#sending the list of elements$stack->push(1,3,5,2,0);echo("Stack top element: ");print_r($stack->peek());?>
Stack top element: 0