Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
queue
push
communitycreator

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

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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

RELATED TAGS

php
queue
push
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring