Monday, December 22, 2025
HomeLanguagesPHP | DsStack isEmpty() Function

PHP | Ds\Stack isEmpty() Function

The Ds\Stack::isEmpty() function of PHP Ds\Stack class is used to check whether a Stack is empty or not. This method returns a boolean value, True if the Stack is empty otherwise it returns False.

Syntax

bool public Ds\Stack::isEmpty ( void )

Parameter: This function does not accept any parameters.
Return Value: This function returns a boolean value True if the stack is Empty otherwise it returns False.

Below programs illustrate the Ds\Stack::isEmpty() function:

Program 1:  

PHP




<?php
 
// PHP program to illustrate the
// Ds\stack::isEmpty() function
 
// Create a Stack instance
$stack = new \Ds\Stack();
 
// Check if stack is Empty
var_dump($stack->isEmpty());
 
// Pushing elements to Stack
$stack->push("Welcome");
$stack->push("to");
$stack->push("GfG");
 
// Check if stack is Empty again
var_dump($stack->isEmpty());
 
?>


Output

bool(true)
bool(false)

Program 2

PHP




<?php
 
// PHP program to illustrate the
// Ds\stack::isEmpty() function
 
// Create a Stack instance
$stack = new \Ds\Stack();
 
// Check if stack is Empty
var_dump($stack->isEmpty());
 
// Pushing Mixed value elements to Stack
$stack->push("Welcome");
$stack->push("to");
$stack->push("GfG");
$stack->push(10);
$stack->push(5.5);
 
// Check if stack is Empty again
var_dump($stack->isEmpty());
 
?>


Output

bool(true)
bool(false)

Reference: http://php.net/manual/en/ds-stack.isempty.php
 

RELATED ARTICLES

Most Popular

Dominic
32456 POSTS0 COMMENTS
Milvus
111 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12038 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6911 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS