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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。