PHP Ds\Deque count()函数用法介绍

2021年4月11日15:42:36 发表评论 851 次浏览

Ds\Deque::count()函数是PHP中的内置函数, 用于获取Deque中的元素数。

语法如下:

public Ds\Deque::count( void ) : int

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

返回值:此函数返回双端队列中的元素数。

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

程序1:

<?php
  
//Declare a deque
$deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]);
  
echo ( "Elements in the Deque\n" );
  
//Display the Deque elements
print_r( $deck );
  
echo ( "\nNumber of elements in the Deque: " );
  
print_r( $deck -> count ());
  
?>

输出如下:

Elements in the Deque
Ds\Deque Object
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
)

Number of elements in the Deque: 6

程序2:

<?php
  
//Declare a deque
$deck = new \Ds\Deque([ "geeks" , "for" , "geeks" ]);
  
echo ( "Elements in the Deque\n" );
  
//Display the Deque elements
print_r( $deck );
  
echo ( "\nNumber of elements in the Deque: " );
  
print_r( $deck -> count ());
  
?>

输出如下:

Elements in the Deque
Ds\Deque Object
(
    [0] => geeks
    [1] => for
    [2] => geeks
)

Number of elements in the Deque: 3

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


木子山

发表评论

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