The Wayback Machine - https://web.archive.org/web/20230421175832/https://www.geeksforgeeks.org/php-dsqueue-pop-function/
Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

PHP Ds\Queue pop() Function

Improve Article
Save Article
Like Article
author
gopaldave
scholar
1293 published articles
Improve Article
Save Article
Like Article

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
 


My Personal Notes arrow_drop_up
Last Updated : 09 Nov, 2020
Like Article
Save Article
Similar Reads