Open In App
Related Articles

PHP | ArrayObject count() Function

Improve Article
Improve
Save Article
Save
Like Article
Like

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" => "GeeksforGeeks"
); 
  
// 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


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks 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!

Last Updated : 27 Sep, 2019
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials