SPL: Using the iteratorAggregate interface
Iterators in PHP5 (Racklin's 阿土伯程式大觀園)
PHP SPL (網站製作學習誌)
//以下程式顯示當前目錄下的第一層目錄及檔案
<?php
$dir = new DirectoryIterator(getcwd());
$dir->rewind();
while ($dir->valid()){
echo $dir->current(), "\n";
$dir->next();
}
foreach ($dir as $entry){
echo $entry . "\n";
}
?>
//以下程式遞迴顯示所有子目錄及檔案
<?php
$dir = new RecursiveDirectoryIterator(getcwd());
$dir->rewind();
while ($dir->valid()){
echo $dir->current(), "\n";
$dir->next();
}
foreach (new RecursiveIteratorIterator($dir) as $entry){
echo "$entry\n";
}
?>
沒有留言:
張貼留言