(PHP 8 >= 8.4.0)
SplObjectStorage::seek — 將迭代器指向指定位置
offset
不回傳任何值。
如果 offset
無法指向,則會拋出 OutOfBoundsException。
範例 #1 SplObjectStorage::seek() 範例
將迭代器指向項目位置 2。
<?php
class Test {
public function __construct(public string $marker) {}
}
$a = new Test("a");
$b = new Test("b");
$c = new Test("c");
$storage = new SplObjectStorage();
$storage[$a] = "first";
$storage[$b] = "second";
$storage[$c] = "third";
$storage->seek(2);
var_dump($storage->key());
var_dump($storage->current());
?>
以上範例會輸出:
int(2) object(Test)#3 (1) { ["marker"]=> string(1) "c" }