DirectoryIterator::seek()函數是PHP中的內置函數,用於將DirectoryIterator項查找到給定位置。
用法:
void DirectoryIterator::seek( int $position )
參數:該函數接受單個參數$position,該參數保存從零開始的數字位置以查找元素。
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的DirectoryIterator::seek()函數:
程序1:
<?php
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
// Move to the third element (0 based indexing)
$directory->seek(2);
// Check for validity of element
if($directory->valid()) {
// Display the filename
echo $directory->getFilename();
}
?>
輸出:
applications.html
程序2:
<?php
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
// Move to the third element (0 based indexing)
$directory->seek(2);
// Check for validity of element
if($directory->valid()) {
// Display the key and filename
echo $directory->key() . " => " .
$directory->getFilename();
}
?>
輸出:
2 => applications.html
注意:此函數的輸出取決於服務器文件夾的內容。
參考: https://www.php.net/manual/en/directoryiterator.seek.php
相關用法
- PHP ArrayIterator seek()用法及代碼示例
- PHP ArrayIterator seek()用法及代碼示例
- PHP SplFileObject seek()用法及代碼示例
- PHP DirectoryIterator key()用法及代碼示例
- PHP DirectoryIterator next()用法及代碼示例
- PHP DirectoryIterator isLink()用法及代碼示例
- PHP DirectoryIterator getCTime()用法及代碼示例
- PHP DirectoryIterator getBasename()用法及代碼示例
- PHP DirectoryIterator current()用法及代碼示例
- PHP DirectoryIterator isDot()用法及代碼示例
- PHP DirectoryIterator getATime()用法及代碼示例
- PHP DirectoryIterator __construct()用法及代碼示例
- PHP DirectoryIterator isFile()用法及代碼示例
- PHP DirectoryIterator isExecutable()用法及代碼示例
- PHP DirectoryIterator isDir()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | DirectoryIterator seek() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。