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


PHP Ds\Stack::count()用法及代碼示例


Ds\Stack::count() 函數可用於計算堆棧中存在的元素數量。

用法

int Ds\Stack::count( void )

Ds\Stack::count() 函數沒有任何參數。

Ds\Stack::count() 函數可以返回堆棧中值的數量。

示例1

<?php  
   $stack = new \Ds\Stack([1, 4, 5, 7, 9, 10]);  
   var_dump($stack);  
   
   echo "The number of elements present in a stack:";  
   print_r($stack->count());  
?>

示例2

<?php  
   $stack = new \Ds\Stack(["Tutorials", "Point", "India"]);  
   print_r($stack);  
  
   echo "The number of elements present in a stack:";  
   var_dump($stack->count());  
?>

相關用法


注:本文由純淨天空篩選整理自 PHP - Ds\Stack::count() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。