Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
communitycreator

What is Ds\Stack::capacity() 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 Stack::capacity() function in PHP returns the number of elements in a stack.

The following illustration shows a visual representation of the Stack::capacity() function.

Figure 1: Visual representation of Stack::capacity() function

Syntax

public Ds\Stack::capacity(): int

Parameters

This function does not require a parameter.

Return value

This function returns the number of elements in the stack.

Code

<?php
$stack1 = new \Ds\Stack();
#sending the list of elements
$stack1->push(1,3,5,2,0);
echo("Stack1 has elements:");
echo($stack1->capacity());
$stack2 = new \Ds\Stack();
echo("\nStack2 has elements:");
echo($stack2->capacity());
?>

Expected output

Stack1 has elements: 5
Stack2 has elements: 0

RELATED TAGS

php
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