PHP Ds Vector count()函数用法介绍

【PHP Ds Vector count()函数用法介绍】Ds \ Vector :: count()function是PHP中的内置函数, 用于计算向量中的元素数。
语法如下:

int public Ds\Vector::count( void )

参数:该函数不接受任何参数。
返回值:此函数返回向量中元素的数量。
下面的程序说明了Ds \ Vector :: count()PHP中的功能:
程序1:
< ?php// Declare a vector $arr1 = new \Ds\Vector([1, 2, 3, 4, 5, 6, 7, 8]); echo ( "Vector elements\n" ); // Display the vector elements print_r( $arr1 ); echo ( "Count vector elements: " ); // Use count() function to count // elements in the vector echo ( count ( $arr1 )); ?>

输出如下:
Vector elements Ds\Vector Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 ) Count vector elements: 8

程式2:
< ?php// Declare a vector $arr1 = new \Ds\Vector([ "geeks" , "for" , "geeks" ]); echo ( "Vector elements\n" ); // Display the vector elements print_r( $arr1 ); echo ( "Count vector elements: " ); // Use count() function to count // elements in the vector echo ( count ( $arr1 )); ?>

输出如下:
Vector elements Ds\Vector Object ( [0] => geeks [1] => for [2] => geeks ) Count vector elements: 3

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

    推荐阅读