Friday, September 5, 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
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6636 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11865 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7026 POSTS0 COMMENTS
Thapelo Manthata
6703 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS