PHP Ds \ Stack类的Ds \ Stack::isEmpty()函数用于检查Stack是否为空。此方法返回一个布尔值,如果Stack为空,则返回True,否则返回False。
用法:
bool public Ds\Stack::isEmpty ( void )
参数:此功能不接受任何参数。
返回值:如果堆栈为空,则此函数返回布尔值True,否则返回False。
以下示例程序旨在说明Ds \ Stack::isEmpty()函数:
程序1::
// PHP program to illustarte the
// 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());
?>
输出:
bool(true)
bool(false)
程序2::
// PHP program to illustarte the
// 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());
?>
输出:
bool(true)
bool(false)