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

The Stack::isEmpty() function in PHP is used to check if a stack is empty. Stack::isEmpty() returns true if the stack is empty. Otherwise, it returns false.

The illustration below shows a visual representation of the Stack::isEmpty() function.

Figure 1: Visual representation of Stack->isEmpty() function

Syntax

stack_name->isEmpty()
## where the stack_name is the name of the stack

Parameter

The Stack::isEmpty() function does not require any parameters.

Return value

The Stack::isEmpty() function returns true (1) if the queue is empty. Otherwise, it returns false.

Code

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

Output

Stack1 is empty:
Stack2 is empty: 1

Free Resources