僅存取目前的資料夾
$max_depth = 0;
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
RecursiveIteratorIterator::setMaxDepth — 設定最大深度
設定允許的最大深度。
此函數目前沒有說明文件;僅提供其參數列表。
maxDepth
允許的最大深度。-1
表示任何深度。
不回傳任何值。
如果 maxDepth
小於 -1
,則會發出 Exception 例外。
我不明白該如何處理這個敘述
RecursiveIteratorIterator::setMaxDepth ([ int $max_depth = -1 ] ) : void
所以,在找到答案之後,以下是您如何使用它(適用於任何像我一樣卡住一段時間的人!)
// 定義您要搜尋的樹狀結構深度
// 其中 -1 = 顯示父項下的所有層級
// 而 1 = 顯示第一層,依此類推
$max_depth = -1;
// 設定目錄的路徑
$this_directory
// 執行搜尋
$recursive = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this_directory));
// 現在將內容調整到您想要的深度
$recursive->setMaxDepth($max_depth);