What is Ds\Stack::capacity() in PHP?

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

Free Resources