FilesystemIterator::rewind()函數是PHP中的一個內置函數,用於回退到文件的開頭。
用法:
void FilesystemIterator::rewind( void )
參數:該函數不接受任何參數。
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的FilesystemIterator::rewind()函數:
示例1:
<?php
// Create new file system iterator
$fileItr = new FilesystemIterator(dirname(__FILE__),
FilesystemIterator::KEY_AS_FILENAME);
// Loop runs while file iterator is valid
while ($fileItr->valid()) {
// Check for non-directory element
if (!$fileItr->isDir()) {
// Display the key
echo $fileItr->key() . "<br>";
}
// Move to the next element
$fileItr->next();
}
// Rewind back to start position
$fileItr->rewind();
// Display the key
echo "<br>After using rewind() function <br>";
echo $fileItr->key();
?>
輸出:
applications.html bitnami.css favicon.ico geeks.html gfg.php index.php After using rewind() function applications.html
示例2:
<?php
// Create new file system iterator
$fileItr = new FilesystemIterator(__DIR__,
FilesystemIterator::CURRENT_AS_PATHNAME);
// Loop runs for each element
foreach($fileItr as $it) {
// Display the current element
echo $fileItr->current() . "<br>";
}
// Rewind back to start position
$fileItr->rewind();
// Display the key
echo "<br>After using rewind() function <br>";
echo $fileItr->key();
?>
輸出:
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
注意:此函數的輸出取決於服務器文件夾的內容。
參考: https://www.php.net/manual/en/filesystemiterator.rewind.php
相關用法
- PHP FilesystemIterator next()用法及代碼示例
- PHP FilesystemIterator key()用法及代碼示例
- PHP FilesystemIterator current()用法及代碼示例
- PHP FilesystemIterator getFlags()用法及代碼示例
- PHP FilesystemIterator __construct()用法及代碼示例
- PHP FilesystemIterator setFlags()用法及代碼示例
- PHP rewind( )用法及代碼示例
- PHP SimpleXMLIterator rewind()用法及代碼示例
- PHP SplObjectStorage rewind()用法及代碼示例
- PHP SplFixedArray rewind()用法及代碼示例
- PHP AppendIterator rewind()用法及代碼示例
- PHP DirectoryIterator rewind()用法及代碼示例
- PHP SplDoublyLinkedList rewind()用法及代碼示例
- PHP SplFileObject rewind()用法及代碼示例
- PHP ArrayIterator rewind()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | FilesystemIterator rewind() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。