Last active
November 8, 2016 17:09
-
-
Save NightZpy/4adc6f02c299c0fec67fa9cf4babc231 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$folder = ['file1.txt', 'file2.txt', 'subfolder1' => ['subfolder2' => ['file3']]] ; | |
$printFolder = function( $folder, $key = 'folder', $i = 0 ) use ( &$printFolder ) | |
{ | |
$tab = str_repeat ('--', $i); | |
if ( isset ( $key ) ) | |
print ( "$tab $key:\n" ); | |
foreach ($folder as $key => $file) { | |
if ( is_array ( $file ) ) { | |
$i++; | |
if ( isset ( $key ) ) | |
$printFolder ( $file, $key, $i ); | |
else | |
$printFolder ( $file, null, $i ); | |
} else { | |
$tab .= '--'; | |
print ( "$tab $file\n" ); | |
} | |
} | |
}; | |
$printFolder ( $folder ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment