PHP - Ds\Pair::isEmpty() 函式



PHP 的Ds\Pair::isEmpty()函式檢查該對是否為空。空對是指不包含任何元素的對。

如果當前對為空,則此函式返回布林值“true”,否則返回“false”。

對類的isEmpty()函式在最新的 PHP 版本中不可用。確保您的系統中安裝了適當版本的 PHP,否則您將遇到一些與錯誤相關的 issue。

語法

以下是 PHP Ds\Pair::isEmpty()函式的語法:

public bool Ds\Pair::isEmpty( void )

引數

此函式不接受任何引數。

返回值

如果該對為空,則此函式返回“true”,否則返回“false”。

示例

以下程式演示了 PHP Ds\Pair::isEmpty()函式的使用:

<?php 
   $pair = new \Ds\Pair("TP", "Tutorialspoint"); 
   echo "The original pair elements are: \n";
   print_r($pair);
   $res = $pair->isEmpty();
   echo "\nIs the pair is empty? ".$res;
?>

輸出

由於此函式在最新的 PHP 版本中不可用,因此它將丟擲以下錯誤:

The original pair elements are:
Ds\Pair Object
(
    [key] => TP
    [value] => Tutorialspoint
)
PHP Fatal error:  Uncaught Error: Call to undefined method Ds\Pair::isEmpty() 
in C:\Apache24\htdocs\index.php:5
Stack trace:
#0 {main}
  thrown in C:\Apache24\htdocs\index.php on line 5
php_function_reference.htm
廣告