PHP | Ds\Stack peek() Function Last Updated : 18 Jan, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. Syntax: 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: Program 1: PHP <?php // PHP program to illustrate the // Ds\stack::peek() function // Create a Stack instance $stack = new \Ds\Stack(); // Pushing elements to Stack $stack->push("Welcome"); $stack->push("to"); $stack->push("GfG"); // Print the top element print_r($stack->peek()); ?> Output: GfG Program 2: PHP <?php // PHP program to illustrate the // Ds\stack::peek() function // Create a Stack instance $stack = new \Ds\Stack(); // Pushing Mixed value elements to Stack $stack->push("Welcome"); $stack->push("to"); $stack->push("GfG"); $stack->push(10); $stack->push(5.5); // Print the top element print_r($stack->peek()); ?> Output: 5.5 Reference: http://php.net/manual/en/ds-stack.peek.php Comment More infoAdvertise with us Next Article PHP DsQueue peek() Function G gopaldave Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_stack Similar Reads PHP | DsStack peek() Function 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. Syntax: mixed public Ds\Stack::peek ( void ) Parameters: This function does not accept any parameters. 1 min read PHP DsQueue peek() Function The Ds\Queue::peek() Function in PHP is used to get the value present at the front of a Queue. This function simply returns the element present at the front of a Queue instance without actually removing it. Syntax: mixed public Ds\Queue::peek ( void ) Parameters: This function does not accepts any p 2 min read PHP | DsDeque set() Function The Ds\Deque::set() function is an inbuilt function in PHP which is used to set the value at the given index in the Deque. Syntax: public Ds\Deque::set( $index, $value ) : void Parameters: This function accept two parameters as mentioned above and described below: index: This parameter holds the ind 2 min read PHP | DsDeque sort() Function The Ds\Deque::sort() function is an inbuilt function in PHP which is used to sort the Deque in place by arranging the elements in increasing order. Syntax: public Ds\Deque::sort( $comparator ) : void Parameters::This function accepts single parameter $comparator which holds the function to decides h 2 min read PHP DsSet get() Function The Ds\Set::get() function of Ds\Set class in PHP is an inbuilt function which is used to get a value from the Set instance. This function is used to fetch a value present at a particular index in the Set instance. Syntax: mixed public Ds\Set::get ( int $index ) Parameters: This function accepts a s 2 min read PHP | DsDeque shift() Function The Ds\Deque::shift() function is an inbuilt function in PHP which is used to remove and return the first value of deque. Syntax: mixed Ds\Deque::shift( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the first value of deque which was removed. Be 1 min read PHP | Ds\Stack peek() Function min read Like