DirectoryIterator::current()函数是PHP中的内置函数,用于返回当前DirectoryIterator项。
用法:
DirectoryIterator DirectoryIterator::current( void )
参数:该函数不接受任何参数。
返回值:此函数返回当前的DirectoryIterator项。
以下示例程序旨在说明PHP中的DirectoryIterator::current()函数:
示例1:
<?php
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
// Loop runs while directory is valid
while ($directory->valid()) {
// Check for directory element
if ($directory->isDir()) {
// Store the current element
$file = $directory->current();
// Display the filename
echo $file->getFilename() . "<br>";
}
// Move to the next element
$directory->next();
}
?>
输出:
. .. dashboard img webalizer xampp
示例2:
<?php
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
// Loop runs for each element of directory
foreach($directory as $dir) {
// Store the current element
$file = $directory->current();
// Display the key and filename
echo $dir->key() . " => " .
$file->getFilename() . "<br>";
}
?>
输出:
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
注意:此函数的输出取决于服务器文件夹的内容。
参考: https://www.php.net/manual/en/directoryiterator.current.php
相关用法
- PHP DirectoryIterator key()用法及代码示例
- PHP DirectoryIterator next()用法及代码示例
- PHP DirectoryIterator isWritable()用法及代码示例
- PHP DirectoryIterator isReadable()用法及代码示例
- PHP DirectoryIterator getType()用法及代码示例
- PHP DirectoryIterator getPerms()用法及代码示例
- PHP DirectoryIterator rewind()用法及代码示例
- PHP DirectoryIterator getSize()用法及代码示例
- PHP DirectoryIterator isLink()用法及代码示例
- PHP DirectoryIterator getCTime()用法及代码示例
- PHP DirectoryIterator getFilename()用法及代码示例
- PHP DirectoryIterator seek()用法及代码示例
- PHP DirectoryIterator getExtension()用法及代码示例
- PHP DirectoryIterator getMTime()用法及代码示例
- PHP DirectoryIterator valid()用法及代码示例
注:本文由纯净天空筛选整理自jit_t大神的英文原创作品 PHP | DirectoryIterator current() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。