PHP | Ds\Vector count() Function
The Ds\Vector::count() function is an inbuilt function in PHP which is used to count the number of elements in the vector.
Syntax:
int public Ds\Vector::count( void )
Parameters: This function does not accepts any parameter.
Return Value: This function returns the number of elements in the vector.
Below programs illustrate the Ds\Vector::count() function in PHP:
Program 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)); ?> |
Output:
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
Program 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)); ?> |
Output:
Vector elements
Ds\Vector Object
(
[0] => geeks
[1] => for
[2] => geeks
)
Count vector elements: 3
Reference: http://php.net/manual/en/ds-vector.count.php
Recommended Posts:
- PHP | Ds\Map count() Function
- PHP | count() Function
- PHP Ds\Set count() Function
- PHP Ds\PriorityQueue count() Function
- PHP | SimpleXMLElement count() Function
- PHP | SplHeap count() Function
- PHP | SplDoublyLinkedList count() function
- PHP | Ds\Stack count() Function
- PHP Ds\Queue count() Function
- PHP | Ds\Deque count() Function
- PHP | SplFixedArray count() Function
- PHP | SplObjectStorage count() Function
- PHP | ArrayObject count() Function
- How to call a function that return another function in JavaScript ?
- CSS | column-count Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



