Thursday, September 4, 2025
HomeLanguagesPHP | ArrayObject count() Function

PHP | ArrayObject count() Function

The ArrayObject::count() function is an inbuilt function in PHP which is used to get the number of public properties in the ArrayObject.

Syntax:

int ArrayObject::count( void )

Parameters: This function does not accept any parameters.

Return Value: This function returns the number of public properties in the ArrayObject.

Below programs illustrate the ArrayObject::count() function in PHP:

Program 1:




<?php 
// PHP program to illustrate the 
// ArrayObject::count() function 
  
// Declare an array and convert it
// into array object
$arrObject = new ArrayObject(
    array('Geeks', 'for', 'Geeks')
); 
  
// Use ArrayObject::count() function
// to count the number of public
// properties in the ArrayObject
$count = $arrObject->count(); 
  
print_r($count); 
  
?> 


Output:

3

Program 2:




<?php 
// PHP program to illustrate the 
// ArrayObject::count() function 
  
// Declare an associative array
$arr = array(
    "a" => "Welcome",
    "b" => "to", 
    "c" => "neveropen"
); 
  
// Create into array object 
$arrObject = new ArrayObject($arr); 
  
// Use ArrayObject::count() function
// to count the number of public
// properties in the ArrayObject
$count = $arrObject->count(); 
  
print_r($count); 
  
?> 


Output:

3

Reference: https://www.php.net/manual/en/arrayobject.count.php

RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6632 POSTS0 COMMENTS
Nicole Veronica
11800 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11860 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS