PHP如何使用SplDoublyLinkedList count()函数?

2021年3月23日15:17:52 发表评论 556 次浏览

SplDoublyLinkedList :: count()函数是PHP中的内置函数, 用于计算双向链表中存在的元素数。

语法如下:

int SplDoublyLinkedList::count( void )

参数:它不包含任何参数。

返回值:它返回双向链表中存在的元素数。

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

程序1:

<?php 
  
// Declare an empty SplDoublyLinkedList
$list = new \SplDoublyLinkedList;
  
// Use SplDoublyLinkedList::add() function to 
// add elements to the SplDoublyLinkedList
$list ->add(0, 30);
$list ->add(1, 20);
$list ->add(2, 30);
$list ->add(3, "Geeks" );
$list ->add(4, 'G' );
  
// Use SplDoublyLinkedList::count() function
// to return number of elements
print_r( $list -> count ());
  
?>

输出如下:

5

程式2:

<?php 
  
// Declare an empty SplDoublyLinkedList
$list = new \SplDoublyLinkedList;
  
// Use SplDoublyLinkedList::push() function to 
// add elements to the SplDoublyLinkedList
$list ->push(1);
$list ->push(2);
$list ->push(3);
$list ->push(8);
$list ->push(5);
  
// Use SplDoublyLinkedList::count() function
// to return number of elements
print_r( $list -> count ());
  
?>

输出如下:

5

参考: https://www.php.net/manual/en/spldoublylinkedlist.count.php


木子山

发表评论

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