CachingIterator::rewind()函數是PHP中的一個內置函數,用於倒帶迭代器。
用法:
void CachingIterator::rewind( void )
參數:該函數不接受任何參數。
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的CachingIterator::rewind()函數:
示例1:
<?php
// Declare an ArrayIterator
$arr = new ArrayIterator(
array(
"a" => 4,
"b" => 2,
"g" => 8,
"d" => 6,
"e" => 1,
"f" => 9
)
);
// Create a new CachingIterator
$cachIt = new CachingIterator(
new ArrayIterator($arr),
CachingIterator::FULL_CACHE
);
// Move to last position
$cachIt->seek(5);
// Display the next value
var_dump($cachIt->next());
// Move to start position
$cachIt->rewind();
// Display the current element
echo $cachIt->current();
?>
輸出:
NULL 4
示例2:
<?php
// Declare an ArrayIterator
$arr = new ArrayIterator(
array(
"b" => "for",
"a" => "Geeks",
"e" => "Science",
"c" => "Geeks",
"f" => "Portal",
"d" => "Computer"
)
);
// Create a new CachingIterator
$cachIt = new CachingIterator(
new ArrayIterator($arr),
CachingIterator::FULL_CACHE
);
// Check the validity of ArrayIterator
while($cachIt->valid()) {
$cachIt->next();
}
// Move to start position
$cachIt->rewind();
// Display the current element
echo $cachIt->current();
?>
輸出:
for
參考: https://www.php.net/manual/en/cachingiterator.rewind.php
相關用法
- PHP CachingIterator key()用法及代碼示例
- PHP CachingIterator next()用法及代碼示例
- PHP CachingIterator getInnerIterator()用法及代碼示例
- PHP CachingIterator __construct()用法及代碼示例
- PHP CachingIterator getFlags()用法及代碼示例
- PHP CachingIterator current()用法及代碼示例
- PHP CachingIterator getCache()用法及代碼示例
- PHP CachingIterator setFlags()用法及代碼示例
- PHP rewind( )用法及代碼示例
- PHP SplDoublyLinkedList rewind()用法及代碼示例
- PHP DirectoryIterator rewind()用法及代碼示例
- PHP FilesystemIterator rewind()用法及代碼示例
- PHP ArrayIterator rewind()用法及代碼示例
- PHP SimpleXMLIterator rewind()用法及代碼示例
- PHP SplFileObject rewind()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | CachingIterator rewind() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。