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
32725 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7103 POSTS0 COMMENTS
Nicole Veronica
12241 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12326 POSTS0 COMMENTS
Shaida Kate Naidoo
7216 POSTS0 COMMENTS
Ted Musemwa
7476 POSTS0 COMMENTS
Thapelo Manthata
7200 POSTS0 COMMENTS
Umr Jansen
7176 POSTS0 COMMENTS