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.
public Ds\Stack::capacity(): int
This function does not require a parameter.
This function returns the number of elements in the stack.
<?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());?>
Stack1 has elements: 5
Stack2 has elements: 0