PHP | FilesystemIterator rewind() Function
Last Updated :
26 Nov, 2019
The FilesystemIterator::rewind() function is an inbuilt function in PHP which is used to rewinds back to the beginning of the file.
Syntax:
void FilesystemIterator::rewind( void )
Parameters: This function does not accept any parameters.
Return Value: This function does not return any value.
Below programs illustrate the FilesystemIterator::rewind() function in PHP:
Program 1:
<?php
$fileItr = new FilesystemIterator(dirname( __FILE__ ),
FilesystemIterator::KEY_AS_FILENAME);
while ( $fileItr ->valid()) {
if (! $fileItr ->isDir()) {
echo $fileItr ->key() . "<br>" ;
}
$fileItr ->next();
}
$fileItr -> rewind ();
echo "<br>After using rewind() function <br>" ;
echo $fileItr ->key();
?>
|
Output:
applications.html
bitnami.css
favicon.ico
geeks.html
gfg.php
index.php
After using rewind() function
applications.html
Program 2:
<?php
$fileItr = new FilesystemIterator(__DIR__,
FilesystemIterator::CURRENT_AS_PATHNAME);
foreach ( $fileItr as $it ) {
echo $fileItr ->current() . "<br>" ;
}
$fileItr -> rewind ();
echo "<br>After using rewind() function <br>" ;
echo $fileItr ->key();
?>
|
Output:
C:\xampp\htdocs\applications.html
C:\xampp\htdocs\bitnami.css
C:\xampp\htdocs\dashboard
C:\xampp\htdocs\favicon.ico
C:\xampp\htdocs\geeks.html
C:\xampp\htdocs\gfg.php
C:\xampp\htdocs\img
C:\xampp\htdocs\index.php
C:\xampp\htdocs\webalizer
C:\xampp\htdocs\xampp
After using rewind() function
C:\xampp\htdocs\applications.html
Note: The output of this function depends on the content of server folder.
Reference: https://www.php.net/manual/en/filesystemiterator.rewind.php
Share your thoughts in the comments
Please Login to comment...