Skip to content

Instantly share code, notes, and snippets.

@NightZpy
Last active November 8, 2016 17:09
Show Gist options
  • Save NightZpy/4adc6f02c299c0fec67fa9cf4babc231 to your computer and use it in GitHub Desktop.
Save NightZpy/4adc6f02c299c0fec67fa9cf4babc231 to your computer and use it in GitHub Desktop.
<?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