PHP Ds\Queue pop() Function

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\PriorityQueue::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 UnderflowException if the Queue is empty.

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

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
  
?> 

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
  
?> 

chevron_right


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

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.