What is Ds\Queue::pop() in PHP?

The Queue::pop() function in PHP returns the element that is available at the front of the queue, and removes that element from the queue.

Figure 1 shows the visual representation of the Queue::pop() function.

Figure 1: Visual representation of Queue::pop() function

Syntax

queue_name->pop()
## where the queue_name is the name of the queue

Parameter

This function does not require a parameter.

Return value

This function returns the element that is available at the front of the queue and removes that element from the queue.

Example

<?php
$queue = new \Ds\Queue();
#sending the list of elements
$queue->push(1,3,5,2,0);
echo("Queue before pop");
print_r($queue);
######output######
#Queue before pop : 1->3->5->2->0
echo("Queue after pop");
$queue->pop()
print_r($queue);
######output######
#Queue after pop : 3->5->2->0
?>

Free Resources