DirectoryIterator::seek()函数是PHP中的内置函数,用于将DirectoryIterator项查找到给定位置。
用法:
void DirectoryIterator::seek( int $position )
参数:该函数接受单个参数$position,该参数保存从零开始的数字位置以查找元素。
返回值:该函数不返回任何值。
以下示例程序旨在说明PHP中的DirectoryIterator::seek()函数:
程序1:
// 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:
// 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
注意:此功能的输出取决于服务器文件夹的内容。