當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP Ds\Deque isEmpty()用法及代碼示例

Ds \ Deque::isEmpty()函數是PHP中的內置函數,用於檢查Deque是否為空。

用法:

public Ds\Deque::isEmpty( void ):bool

參數:該函數不接受任何參數。


返回值:如果雙端隊列為空,則此函數返回true,否則返回false。

以下示例程序旨在說明PHP中的Ds \ Deque::isEmpty()函數:

程序1:

<?php 
  
// Declare a deque 
$deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]); 
  
echo("Original Deque\n"); 
  
// Display the Deque elements 
print_r($deck); 
  
// Use isEmpty() function to check 
// the deque is empty or not 
var_dump($deck->isEmpty()); 
  
?>
輸出:
Original Deque
Ds\Deque Object
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
)
bool(false)

程序2:

<?php 
  
// Declare a deque 
$deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]); 
  
echo("Original Deque\n"); 
  
// Display the Deque elements 
print_r($deck); 
  
// Clearing the Deque 
$deck->clear(); 
  
// Use isEmpty() function to check 
// the deque is empty or not 
var_dump($deck->isEmpty()); 
  
?>
輸出:
Original Deque
Ds\Deque Object
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
)
bool(true)

參考: http://php.net/manual/en/ds-deque.isempty.php



相關用法


注:本文由純淨天空篩選整理自barykrg大神的英文原創作品 PHP | Ds\Deque isEmpty() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。