The SplObjectStorage::count() function is an inbuilt function in PHP which is used to count the number of objects in storage.
Syntax:
int SplObjectStorage::count()
Parameters: This function does not contains any parameter.
Return Value: This function returns number of objects in storage.
Below programs illustrate the SplObjectStorage::count() function in PHP:
Program 1:
<?php
$gfg = new SplObjectStorage();
$gfg1 = new StdClass;
$gfg2 = new StdClass;
$gfg3 = new StdClass;
$gfg ->attach( $gfg1 );
$gfg ->attach( $gfg2 );
$gfg ->attach( $gfg3 );
var_dump( $gfg -> count ());
?>
|
Program 2:
<?php
$gfg = new SplObjectStorage();
$gfg1 = new StdClass;
$gfg2 = new StdClass;
$gfg3 = new StdClass;
$gfg ->attach( $gfg1 );
$gfg ->attach( $gfg2 );
$gfg ->attach( $gfg3 );
var_dump( count ( $gfg ));
?>
|
Reference: https://www.php.net/manual/en/splobjectstorage.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 :
23 Jun, 2023
Like Article
Save Article