Open In App

PHP Ds\Queue pop() Function

Improve
Improve
Like Article
Like
Save
Share
Report

The Ds\Queue::pop() Function in PHP is used to remove and return the value present at the top of the Queue. In other words, it returns the value present at the front of the Queue and also removes it from the Queue.

Syntax: 

mixed public Ds\Queue::pop ( void )

Parameters: This function does not accepts any parameters.

Return Value: This function returns the value with present at the top of the Queue. The return type of the function is mixed and depends on the type of value stored in the Queue.

Exception: This function throws an Underflow Exception if the Queue is empty.

Below programs illustrate the Ds\Queue::pop() Function in PHP:

Program 1:  

PHP




<?php
 
// Declare new Queue
$q = new \Ds\Queue();
 
// Add elements to the Queue
$q->push("One");
$q->push("Two");
$q->push("Three");
 
echo "Initial Queue is: \n";
print_r($q);
 
// Pop an element
echo "\nPopped element is: ";
print_r($q->pop());
 
echo "\n\nFinal Queue is: \n";
print_r($q);
 
?>


Output: 

Initial Queue is: 
Ds\Queue Object
(
    [0] => One
    [1] => Two
    [2] => Three
)

Popped element is: One

Final Queue is: 
Ds\Queue Object
(
    [0] => Two
    [1] => Three
)





 

Program 2: 

PHP




<?php
 
// Declare new Queue
$q = new \Ds\Queue();
 
// Add elements to the Queue
$q->push("Geeks");
$q->push("for");
$q->push("Geeks");
 
echo "Initial Queue is: \n";
print_r($q);
 
// Pop an element
echo "\nPopped element is: ";
print_r($q->pop());
 
echo "\n\nFinal Queue is: \n";
print_r($q);
 
?>


Output: 

Initial Queue is: 
Ds\Queue Object
(
    [0] => Geeks
    [1] => for
    [2] => Geeks
)

Popped element is: Geeks

Final Queue is: 
Ds\Queue Object
(
    [0] => for
    [1] => Geeks
)





 

Reference: http://php.net/manual/en/ds-queue.pop.php
 



Last Updated : 09 Nov, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads