Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
queue
count
communitycreator

What is Ds\Queue::count() 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::count() function in PHP returns the number of elements in a queue. In short, this function is used to get the current size of the queue.

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

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

Syntax

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

Parameter

This function does not require a parameter.

Return value

This function returns the number of elements in the queue because it is used to get the current size of the queue.

Example

<?php
$queue1 = new \Ds\Queue();
#sending the list of elements
$queue->push(1,3,5,2,0);
echo("Queue1 has elements:");
echo($queue1->count());
######output######
#Queue1 has elements : 5
$queue2 = new \Ds\Queue();
echo("Queue2 has elements:");
echo($queue2->count());
######output######
#Queue2 has elements : 0
?>

RELATED TAGS

php
queue
count
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