例如價值觀,我有數組簡單數組關聯數組,基於「目錄樹」喜歡的第一個
Array
(
[0] => folder1/file1.txt
[1] => folder1/file2.txt
[2] => file2.txt
[3] => folder2/file1.txt
[4] => folder1/subfolder1/file1.txt
[5] => folder1/subfolder2/file2.txt
[6] => file1.txt
[7] => file3.txt
[8] => folder1/subfolder2/file1.txt
)
我需要一個線索人物如何創建「目錄樹」陣列,基於在給定的值,它可能看起來像這樣:
Array
(
[folder1] => Array
(
[0] => file1.txt
[1] => file2.txt
[subfolder1] => Array
(
[0] => file1.txt
)
[subfolder2] => Array
(
[0] => file1.txt
[1] => file2.txt
)
)
[0] => file1.txt
[1] => file2.txt
[2] => file3.txt
)
現在第二個數組是第一個數組的樹(手動)。 =)
而我不知道如何自動實現這一點。
可能的誘惑[http://stackoverflow.com/questions/8479543/php-how-to-populate-a-directory-structure-in-an-array](http://stackoverflow.com/questions/ 8479543/PHP-如何到填充-A-目錄 - 結構 - 在-一個陣列)? –
@Kristen Jukowski該主題涉及真正的文件和目錄,我沒有 –
@KristenJukowski該問題始於遞歸目錄迭代器,此問題以平面數組開頭。我很確定我回答了一個類似的問題,我試圖找到它。 – Barmar