SplObjectStorage::offsetUnset()函數是PHP中的內置函數,用於從存儲中設置對象。
用法:
void SplObjectStorage::offsetUnset( $object )
參數:該函數接受單個參數$object,該參數指定要取消設置的。
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的SplObjectStorage::offsetUnset()函數:
程序1:
<?php
// Create an empty SplObjectStorage
$str = new SplObjectStorage;
$obj = new StdClass;
// Set offset $obj to $str
$str->attach($obj, "GeeksforGeeks");
// Print Result before
var_dump(count($str));
// Unset object from storage
$str->offsetUnset($obj);
// Print Result after
var_dump(count($str));
?>
輸出:
int(1) int(0)
程序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");
// Print Result before
var_dump(count($str));
// Unset object from storage
$str->offsetUnset($obj1);
$str->offsetUnset($obj2);
$str->offsetUnset($obj3);
$str->offsetUnset($obj4);
// Print Result after
var_dump(count($str));
?>
輸出:
int(4) int(0)
參考: https://www.php.net/manual/en/splobjectstorage.offsetunset.php
相關用法
- PHP ArrayObject offsetUnset()用法及代碼示例
- PHP SplDoublyLinkedList offsetUnset()用法及代碼示例
- PHP SplFixedArray offsetUnset()用法及代碼示例
- PHP ArrayIterator offsetUnset()用法及代碼示例
- PHP SplObjectStorage next()用法及代碼示例
- PHP SplObjectStorage key()用法及代碼示例
- PHP SplObjectStorage contains()用法及代碼示例
- PHP SplObjectStorage valid()用法及代碼示例
- PHP SplObjectStorage count()用法及代碼示例
- PHP SplObjectStorage getinfo()用法及代碼示例
- PHP SplObjectStorage current()用法及代碼示例
- PHP SplObjectStorage attach()用法及代碼示例
- PHP SplObjectStorage detach()用法及代碼示例
- PHP SplObjectStorage rewind()用法及代碼示例
- PHP SplObjectStorage removeAllExcept()用法及代碼示例
注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | SplObjectStorage offsetUnset() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。