PHP | DirectoryIterator next() Function
Last Updated :
26 Nov, 2019
The DirectoryIterator::next() function is an inbuilt function in PHP which is used to move forward to the next DirectoryIterator item.
Syntax:
void DirectoryIterator::next( void )
Parameters: This function does not accept any parameters.
Return Value: This function does not return any value.
Below programs illustrate the DirectoryIterator::next() function in PHP:
Program 1:
<?php
$directory = new DirectoryIterator(dirname( __FILE__ ));
while ( $directory ->valid()) {
if ( $directory ->isDir()) {
echo $directory ->key() . " => " .
$directory ->getFilename() . "<br>" ;
}
$directory ->next();
}
?>
|
Output:
0 => .
1 => ..
4 => dashboard
8 => img
11 => webalizer
12 => xampp
Program 2:
<?php
$directory = new DirectoryIterator(dirname( __FILE__ ));
while ( $directory ->valid()) {
if ( $directory ->isFile()) {
echo $directory ->getFilename() . "<br>" ;
}
$directory ->next();
}
?>
|
Output:
applications.html
bitnami.css
favicon.ico
geeks.PNG
gfg.php
index.php
Sublime Text Build 3211 x64 Setup.exe
Note: The output of this function depends on the content of server folder.
Reference: https://www.php.net/manual/en/directoryiterator.next.php
Share your thoughts in the comments
Please Login to comment...