SplObjectStorage::getinfo()函數是PHP中的一個內置函數,用於通過當前迭代器位置獲取與對象關聯的數據。
用法:
mixed SplObjectStorage::getinfo()
參數:該函數不接受任何參數。
返回值:此函數返回當前迭代器位置關聯的對象。
以下程序說明了PHP中的SplObjectStorage::getinfo()函數:
示例1:
<?php
// Create New Empty Storage Class
$str = new SplObjectStorage();
$obj1 = new StdClass;
$str->attach($obj1, "GeksforGeeks");
$str->rewind();
$object = $str->current();
// Get info into $data
$data = $str->getInfo();
// Print Result
var_dump($object);
var_dump($data);
?>
輸出:
object(stdClass)#2 (0) { } string(12) "GeksforGeeks"
示例2:
<?php
// Create an Empty SplObjectStorage
$str = new SplObjectStorage();
$obj1 = new StdClass;
$obj2 = new StdClass;
$obj3 = new StdClass;
$obj4 = new StdClass;
$str->attach($obj1, "GeksforGeeks");
$str->attach($obj2, "GFG");
$str->attach($obj3);
$str->attach($obj4, "DSA");
$str->rewind();
// Iterate and print data on each index
while($str->valid()) {
$index = $str->key();
$object = $str->current();
$data = $str->getInfo();
var_dump($object);
var_dump($data);
$str->next();
}
?>
輸出:
object(stdClass)#2 (0) { } string(12) "GeksforGeeks" object(stdClass)#3 (0) { } string(3) "GFG" object(stdClass)#4 (0) { } NULL object(stdClass)#5 (0) { } string(3) "DSA"
參考: https://www.php.net/manual/en/splobjectstorage.getinfo.php
相關用法
- PHP SplObjectStorage contains()用法及代碼示例
- PHP SplObjectStorage next()用法及代碼示例
- PHP SplObjectStorage key()用法及代碼示例
- PHP SplObjectStorage rewind()用法及代碼示例
- PHP SplObjectStorage removeAllExcept()用法及代碼示例
- PHP SplObjectStorage serialize()用法及代碼示例
- PHP SplObjectStorage removeAll()用法及代碼示例
- PHP SplObjectStorage detach()用法及代碼示例
- PHP SplObjectStorage offsetSet()用法及代碼示例
- PHP SplObjectStorage offsetExists()用法及代碼示例
- PHP SplObjectStorage offsetGet()用法及代碼示例
- PHP SplObjectStorage offsetUnset()用法及代碼示例
- PHP SplObjectStorage count()用法及代碼示例
- PHP SplObjectStorage current()用法及代碼示例
- PHP SplObjectStorage attach()用法及代碼示例
注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | SplObjectStorage getinfo() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。