Thursday, July 23, 2026
HomeLanguagesPHP | DsVector count() Function

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(["neveropen", "for", "neveropen"]);
  
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] => neveropen
    [1] => for
    [2] => neveropen
)
Count vector elements: 3

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6902 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6971 POSTS0 COMMENTS