SplObjectStorage::count()函数是PHP中的一个内置函数,用于计算存储中的对象数。
用法:
int SplObjectStorage::count()
参数:该函数不包含任何参数。
返回值:此函数返回存储中的对象数。
以下程序说明了PHP中的SplObjectStorage::count()函数:
示例1:
<?php
// Declare Empty SplObjectStorage
$gfg = new SplObjectStorage();
$gfg1 = new StdClass;
$gfg2 = new StdClass;
$gfg3 = new StdClass;
// Add object to SplObjectStorage class
$gfg->attach($gfg1);
$gfg->attach($gfg2);
$gfg->attach($gfg3);
// Use count() function to count object
var_dump($gfg->count());
?>
输出:
int(3)
示例2:
<?php
// Declare Empty SplObjectStorage
$gfg = new SplObjectStorage();
$gfg1 = new StdClass;
$gfg2 = new StdClass;
$gfg3 = new StdClass;
// Add object to SplObjectStorage class
$gfg->attach($gfg1);
$gfg->attach($gfg2);
$gfg->attach($gfg3);
// Use count in different way
// Passing object as parameter
var_dump(count($gfg));
?>
输出:
int(3)
参考: https://www.php.net/manual/en/splobjectstorage.count.php
相关用法
- PHP SplObjectStorage next()用法及代码示例
- PHP SplObjectStorage key()用法及代码示例
- PHP SplObjectStorage contains()用法及代码示例
- PHP SplObjectStorage offsetGet()用法及代码示例
- PHP SplObjectStorage rewind()用法及代码示例
- PHP SplObjectStorage serialize()用法及代码示例
- PHP SplObjectStorage setInfo()用法及代码示例
- PHP SplObjectStorage unserialize()用法及代码示例
- PHP SplObjectStorage removeAllExcept()用法及代码示例
- PHP SplObjectStorage offsetExists()用法及代码示例
- PHP SplObjectStorage offsetUnset()用法及代码示例
- PHP SplObjectStorage removeAll()用法及代码示例
- PHP SplObjectStorage offsetSet()用法及代码示例
- PHP SplObjectStorage addAll()用法及代码示例
- PHP SplObjectStorage current()用法及代码示例
注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | SplObjectStorage count() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。