SplObjectStorage::offsetGet()函數是PHP中的內置函數,用於獲取與對象關聯的數據。
用法:
object SplObjectStorage::offsetGet($obj)
參數:該函數接受單個參數$obj,該參數指定要獲取的對象。
返回值:此函數返回先前與存儲中的對象關聯的數據。
以下示例程序旨在說明PHP中的SplObjectStorage::offsetGet()函數:
程序1:
<?php
// Create an empty SplObjectStorage
$str = new SplObjectStorage;
$obj = new StdClass;
// Attch $obj to $str
$str->attach($obj, "GeeksforGeeks");
// Print Result
var_dump($str->offsetGet($obj));
?>
輸出:
string(13) "GeeksforGeeks"
程序2:
<?php
// Create an Empty SplObjectStorage
$str = new SplObjectStorage();
$obj1 = new StdClass;
$obj2 = new StdClass;
$obj3 = new StdClass;
$obj4 = new StdClass;
// Attach objects
$str->attach($obj1, "GeksforGeeks");
$str->attach($obj2, "GFG");
$str->attach($obj3);
$str->attach($obj4, "Hello GFG");
// Print result
var_dump($str->offsetGet($obj1));
var_dump($str->offsetGet($obj2));
var_dump($str->offsetGet($obj4));
var_dump($str->offsetGet($obj3));
?>
輸出:
string(12) "GeksforGeeks" string(3) "GFG" string(9) "Hello GFG" NULL
參考: https://www.php.net/manual/en/splobjectstorage.offsetget.php
相關用法
- PHP ArrayObject offsetGet()用法及代碼示例
- PHP SplDoublyLinkedList offsetGet()用法及代碼示例
- PHP ArrayIterator offsetGet()用法及代碼示例
- PHP SplFixedArray offsetGet()用法及代碼示例
- PHP SplObjectStorage key()用法及代碼示例
- PHP SplObjectStorage next()用法及代碼示例
- PHP SplObjectStorage contains()用法及代碼示例
- PHP SplObjectStorage serialize()用法及代碼示例
- PHP SplObjectStorage valid()用法及代碼示例
- PHP SplObjectStorage detach()用法及代碼示例
- PHP SplObjectStorage addAll()用法及代碼示例
- PHP SplObjectStorage count()用法及代碼示例
- PHP SplObjectStorage attach()用法及代碼示例
- PHP SplObjectStorage current()用法及代碼示例
- PHP SplObjectStorage removeAll()用法及代碼示例
注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | SplObjectStorage offsetGet() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。