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

The Queue::push() function in PHP is used to insert an element or list of elements at the back of the priority queue.

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

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

Syntax

queue_name->push(element(s))
// where the queue_name is the name of the queue

Parameter

This function requires an element or list of elements separated by commas as a parameter.

Return value

This function inserts the element or list of elements sent as a parameter at the back of the priority queue.

Example

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

Free Resources