SplObjectStorage::setInfo()函數是PHP中的內置函數,用於設置與當前迭代器條目關聯的數據。
用法:
void SplObjectStorage::setInfo( $val )
參數:該函數接受單個參數$val,該參數指定要與存儲的當前迭代器條目關聯的數據。
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的SplObjectStorage::setInfo()函數:
程序1:
<?php
$str = new SplObjectStorage();
$obj1 = new StdClass;
$str->attach($obj1, "GeeksforGeeks");
$str->rewind();
// Set new info for $obj1 in storage $str
$str->setInfo("new_GeeksforGeeks");
// Print Result
var_dump($str[$obj1]);
?>
輸出:
string(17) "new_GeeksforGeeks"
程序2:
<?php
$obj1 = new StdClass;
$obj2 = new StdClass;
$obj3 = new StdClass;
$gfg = new SplObjectStorage();
$gfg[$obj1] = "GFG";
$gfg[$obj2] = "GeeksClasses";
$gfg[$obj3] = "SUDO";
// Using rewind function
$gfg->rewind();
while($gfg->valid()) {
$gfg->setInfo("Modified_GFG_DATA");
var_dump($gfg->getInfo());
// Moving to next element
$gfg->next();
}
?>
輸出:
string(17) "Modified_GFG_DATA" string(17) "Modified_GFG_DATA" string(17) "Modified_GFG_DATA"
參考: https://www.php.net/manual/en/splobjectstorage.setinfo.php
相關用法
- PHP SplObjectStorage next()用法及代碼示例
- PHP SplObjectStorage contains()用法及代碼示例
- PHP SplObjectStorage key()用法及代碼示例
- PHP SplObjectStorage serialize()用法及代碼示例
- PHP SplObjectStorage detach()用法及代碼示例
- PHP SplObjectStorage unserialize()用法及代碼示例
- PHP SplObjectStorage current()用法及代碼示例
- PHP SplObjectStorage offsetGet()用法及代碼示例
- PHP SplObjectStorage getinfo()用法及代碼示例
- PHP SplObjectStorage offsetExists()用法及代碼示例
- PHP SplObjectStorage offsetSet()用法及代碼示例
- PHP SplObjectStorage offsetUnset()用法及代碼示例
- PHP SplObjectStorage rewind()用法及代碼示例
- PHP SplObjectStorage removeAllExcept()用法及代碼示例
- PHP SplObjectStorage removeAll()用法及代碼示例
注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | SplObjectStorage setInfo() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。