📜  PHP | DirectoryIterator rewind()函数

📅  最后修改于: 2022-05-13 01:56:30.748000             🧑  作者: Mango

PHP | DirectoryIterator rewind()函数

DirectoryIterator::rewind()函数是PHP中的一个内置函数,用于将 DirectoryIterator 倒回到起始位置。

句法:

void DirectoryIterator::rewind( void )

参数:此函数不接受任何参数。

返回值:此函数不返回任何值。

下面的程序说明了PHP中的 DirectoryIterator::rewind()函数:

方案一:

valid()) {
      
    // Check the element is directory
    if($directory->isDir()) {
  
        // Display the key and file name
        echo $directory->key() . " => " . 
        $directory->getFilename() . "
";     }        // Move to the next element     $directory->next(); }    // Use rewind() function to move to // the start position $directory->rewind();    // Display the key and file name echo $directory->key() . " => " .          $directory->getFilename();    ?>

输出:

0 => .
1 => ..
4 => dashboard
8 => img
11 => webalizer
12 => xampp
0 => .

方案二:

key() . " => " . 
    $dir->getFilename() . "
"; }    // Use rewind() function to move to // the start position $directory->rewind();    // Display key and file name echo $directory->key() . " => " .          $directory->getFilename();    ?>

输出:

0 => .
1 => ..
2 => applications.html
3 => bitnami.css
4 => dashboard
5 => favicon.ico
6 => geeks.PNG
7 => gfg.php
8 => img
9 => index.php
10 => Sublime Text Build 3211 x64 Setup.exe
11 => webalizer
12 => xampp
0 => .

注意:此函数的输出取决于服务器文件夹的内容。

参考: https://www. PHP.net/manual/en/directoryiterator.rewind。 PHP