PHP Ds Queue count()函数

2021年3月10日16:14:56 发表评论 703 次浏览

Ds \ Queue :: count()PHP中的函数用于获取Queue实例中存在的元素数。

语法如下:

int public Ds\Queue::count ( void )

参数:该函数不接受任何参数。

返回值:此函数计算Queue实例中存在的元素数并返回计数。

下面的程序说明了Ds \ Queue :: count()PHP中的功能:

程序1:

<?php 
  
// Declare new Queue   
$q = new \Ds\Queue(); 
  
// Add elements to the Queue 
$q ->push( "One" );
$q ->push( "Two" );
$q ->push( "Three" );
  
// Count the number of elements 
// in this Queue 
print_r( $q -> count ());
  
?>

输出如下:

3

程式2:

<?php 
  
// Declare new Queue 
$q = new \Ds\Queue(); 
  
// Add elements to the Queue 
$q ->push( "Geeks" );
$q ->push( "for" );
$q ->push( "Geeks" );
  
// Count the number of elements 
// in this Queue 
print_r( $q -> count ());
  
?>

输出如下:

3

参考:http://php.net/manual/en/ds-priorityqueue.count.php


木子山

发表评论

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