PHP | CachingIterator rewind()函数
CachingIterator::rewind()函数是PHP中的一个内置函数,用于回退迭代器。
句法:
void CachingIterator::rewind( void )
参数:此函数不接受任何参数。
返回值:此函数不返回任何值。
下面的程序说明了PHP中的 CachingIterator::rewind()函数:
方案一:
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
方案二:
"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