DirectoryIterator::__construct()函數是PHP中的內置函數,用於從路徑構造新的目錄迭代器。
用法:
public DirectoryIterator::__construct( string $path )
參數:該函數接受單個參數$path,該參數保存要遍曆的目錄的路徑。
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的DirectoryIterator::__construct()函數:
程序1:
<?php
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
// Loop runs for each element of directory
foreach ($directory as $dir) {
// Check if directory element is valid
if ($dir->valid()) {
// Display the filename
echo $dir->getFilename() . "<br>";
}
}
?>
輸出:
. .. applications.html bitnami.css dashboard favicon.ico geeks.PNG gfg.php img index.php Sublime Text Build 3211 x64 Setup.exe webalizer xampp
程序2:
<?php
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
// Loop runs while directory is valid
while ($directory->valid()) {
// Check or directory element
if ($directory->isDir()) {
// Display the filename
echo $directory->getFilename() . "<br>";
}
// Move to the next element
$directory->next();
}
?>
輸出:
. .. dashboard img webalizer xampp
注意:此函數的輸出取決於服務器文件夾的內容。
參考: https://www.php.net/manual/en/directoryiterator.construct.php
相關用法
- PHP DirectoryIterator key()用法及代碼示例
- PHP DirectoryIterator next()用法及代碼示例
- PHP DirectoryIterator rewind()用法及代碼示例
- PHP DirectoryIterator getCTime()用法及代碼示例
- PHP DirectoryIterator getBasename()用法及代碼示例
- PHP DirectoryIterator isDot()用法及代碼示例
- PHP DirectoryIterator getType()用法及代碼示例
- PHP DirectoryIterator isReadable()用法及代碼示例
- PHP DirectoryIterator isExecutable()用法及代碼示例
- PHP DirectoryIterator isFile()用法及代碼示例
- PHP DirectoryIterator getPathname()用法及代碼示例
- PHP DirectoryIterator getPerms()用法及代碼示例
- PHP DirectoryIterator getSize()用法及代碼示例
- PHP DirectoryIterator getPath()用法及代碼示例
- PHP DirectoryIterator isWritable()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | DirectoryIterator __construct() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。