PHP | Ds\Vector count() Function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 <?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 <?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: https://www.php.net/manual/en/ds-vector.count.php Comment More infoAdvertise with us Next Article PHP | DsStack count() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_vector Similar Reads PHP DsSet count() Function The Ds\Set::count() function of Ds\Set class in PHP is an inbuilt function which is used to count the number of values present in the Set. This is also referred to as the size of the Set instance. Syntax: int public Ds\Set::count() Parameters: This function does not accept any parameter. Return Valu 1 min read PHP substr_count() Function The substr_count() is a built-in function in PHP and is used to count the number of times a substring occurs in a given string. The function also provides us with an option to search for the given substring in a given range of the index. It is case sensitive, i.e., "abc" substring is not present in 3 min read PHP | DsDeque count() Function The Ds\Deque::count() function is an inbuilt function in PHP which is used to get the number of elements in the Deque. Syntax: public Ds\Deque::count( void ) : int Parameters: This function does not accept any parameter. Return Value: This function returns the number of elements in the Deque. Below 1 min read PHP | DsStack count() Function The Ds\Stack::count() function is an inbuilt function in PHP which is used to count the number of elements present in the Stack. Syntax: int Ds\Stack::count( void ) Parameters: This function does not accept any parameter. Return Value: This function returns the number of elements present in the Stac 1 min read PHP count() Function The count() function in PHP is used to count the number of elements in an array or the countable properties of an object. The function returns an integer value representing the number of items present.Syntax:count($array, mode)In this syntax:$array (mandatory): Refers to the array, whose elements ar 3 min read PHP DsQueue count() Function The Ds\Queue::count() Function in PHP is used to get the count of elements present in a Queue instance. Syntax: int public Ds\Queue::count ( void ) Parameters: This function does not accepts any parameters. Return Value: This function calculates the number of elements present in a Queue instance and 1 min read Like