PHP如何使用Ds Stack isEmpty()函数?

2021年3月23日14:34:53 发表评论 558 次浏览

Ds \ Stack :: isEmpty()PHP Ds \ Stack类的函数用于检查Stack是否为空。此方法返回一个布尔值, 如果堆为空, 则返回True, 否则返回False。

语法:

bool public Ds\Stack::isEmpty ( void )

参数:此功能不接受任何参数。

返回值:如果堆为空, 则此函数返回布尔值True, 否则返回False。

下面的程序说明了Ds \ Stack :: isEmpty()功能:

程序1:

<?php
  
// 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
  
// 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)

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


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: