Thursday, October 16, 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
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS