PHP | CachingIterator rewind() Function
Last Updated :
26 Nov, 2019
The CachingIterator::rewind() function is an inbuilt function in PHP which is used to rewind the iterator.
Syntax:
void CachingIterator::rewind( void )
Parameters: This function does not accept any parameters.
Return Value: This function does not return any value.
Below programs illustrate the CachingIterator::rewind() function in PHP:
Program 1:
<?php
$arr = new ArrayIterator(
array (
"a" => 4,
"b" => 2,
"g" => 8,
"d" => 6,
"e" => 1,
"f" => 9
)
);
$cachIt = new CachingIterator(
new ArrayIterator( $arr ),
CachingIterator::FULL_CACHE
);
$cachIt ->seek(5);
var_dump( $cachIt ->next());
$cachIt -> rewind ();
echo $cachIt ->current();
?>
|
Program 2:
<?php
$arr = new ArrayIterator(
array (
"b" => "for" ,
"a" => "Geeks" ,
"e" => "Science" ,
"c" => "Geeks" ,
"f" => "Portal" ,
"d" => "Computer"
)
);
$cachIt = new CachingIterator(
new ArrayIterator( $arr ),
CachingIterator::FULL_CACHE
);
while ( $cachIt ->valid()) {
$cachIt ->next();
}
$cachIt -> rewind ();
echo $cachIt ->current();
?>
|
Reference: https://www.php.net/manual/en/cachingiterator.rewind.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...