The Ds\Stack::peek() function of PHP is used to get the element present at the top of the Stack instance. This function just returns the top element of the stack without removing it from the stack.
mixed public Ds\Stack::peek ( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns the element present at the top of the Stack.
Below programs illustrate the Ds\Stack::peek() function in PHP:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.