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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
