SplObjectStorage::rewind()函数是PHP中的内置函数,用于将迭代器倒回第一个存储元素。
用法:
void SplObjectStorage::rewind()
参数:该函数不接受任何参数。
返回值:该函数不返回任何值。
以下程序说明了PHP中的SplObjectStorage::rewind()函数:
示例1:
<?php
// Create an empty SplObjectStorage
$str = new SplObjectStorage();
$obj = new StdClass;
$obj2 = new StdClass;
$obj3 = new StdClass;
$str->attach($obj, "GFG");
$str->attach($obj2, "Geeks");
$str->attach($obj3, "FORK JAVA");
// Using rewind function
$str->rewind();
// Get current data
var_dump($str->getInfo());
// Move on to next object
$str->next();
// Get current data
var_dump($str->getInfo());
// Again using rewind function
$str->rewind();
// Get current data
var_dump($str->getInfo());
?>
输出:
string(3) "GFG" string(5) "Geeks" string(3) "GFG"
示例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()) {
var_dump($gfg->getInfo());
// Moving to next element
$gfg->next();
}
?>
输出:
string(3) "GFG" string(12) "GeeksClasses" string(4) "SUDO"
参考: https://www.php.net/manual/en/splobjectstorage.rewind.php
相关用法
- PHP rewind( )用法及代码示例
- PHP SimpleXMLIterator rewind()用法及代码示例
- PHP ArrayIterator rewind()用法及代码示例
- PHP FilesystemIterator rewind()用法及代码示例
- PHP DirectoryIterator rewind()用法及代码示例
- PHP SplFixedArray rewind()用法及代码示例
- PHP AppendIterator rewind()用法及代码示例
- PHP SplDoublyLinkedList rewind()用法及代码示例
- PHP CachingIterator rewind()用法及代码示例
- PHP SplFileObject rewind()用法及代码示例
- PHP SplObjectStorage key()用法及代码示例
- PHP SplObjectStorage next()用法及代码示例
- PHP SplObjectStorage contains()用法及代码示例
- PHP SplObjectStorage offsetGet()用法及代码示例
- PHP SplObjectStorage offsetUnset()用法及代码示例
注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | SplObjectStorage rewind() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。