Ds \ Vector::count()函数是PHP中的一个内置函数,用于计算向量中的元素数。
用法:
int public Ds\Vector::count( void )
参数:该函数不接受任何参数。
返回值:此函数返回向量中元素的数量。
以下示例程序旨在说明PHP中的Ds \ Vector::count()函数:
程序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
相关用法
- PHP Ds\Set count()用法及代码示例
- PHP Ds\Map count()用法及代码示例
- PHP count()用法及代码示例
- PHP ArrayIterator count()用法及代码示例
- PHP Ds\Stack count()用法及代码示例
- PHP SplObjectStorage count()用法及代码示例
- PHP SplHeap count()用法及代码示例
- PHP Ds\Deque count()用法及代码示例
- PHP SplFixedArray count()用法及代码示例
- PHP SplDoublyLinkedList count()用法及代码示例
- PHP Ds\Queue count()用法及代码示例
- PHP ArrayObject count()用法及代码示例
- PHP SimpleXMLElement count()用法及代码示例
- PHP Ds\PriorityQueue count()用法及代码示例
注:本文由纯净天空筛选整理自barykrg大神的英文原创作品 PHP | Ds\Vector count() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
