Created
November 29, 2012 21:37
-
-
Save timw4mail/4172083 to your computer and use it in GitHub Desktop.
Create directory structure in php
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 | |
/** | |
* Creates directories based on the array given | |
* | |
* @param array $structure | |
* @param string $path | |
* @return void | |
*/ | |
function make_dir_tree($structure, $path=__DIR__) | |
{ | |
foreach ($structure as $folder => $sub_folder) | |
{ | |
// Folder with subfolders | |
if (is_array($sub_folder)) | |
{ | |
$new_path = "{$path}/{$folder}"; | |
if ( ! is_dir($new_path)) mkdir($new_path); | |
call_user_func(__FUNCTION__, $sub_folder, $new_path); | |
} | |
else | |
{ | |
$new_path = "{$path}/{$sub_folder}"; | |
if ( ! is_dir($new_path)) mkdir($new_path); | |
} | |
} | |
} |
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 | |
$dir_tree = [ | |
'OpenSQLManager.app' => [ | |
'Contents' => [ | |
'Frameworks', | |
'Resources' => [ | |
'images' | |
], | |
'MacOS' => [ | |
'sys' => [ | |
'common', | |
'db' => [ | |
'classes', | |
'drivers' => [ | |
'mysql', | |
'pgsql', | |
'sqlite', | |
'odbc', | |
'firebird' | |
] | |
], | |
'widgets', | |
'windows' | |
] | |
] | |
] | |
] | |
]; | |
make_dir_tree($dir_tree); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
call_user_func
Why this is used?and what is -- FUNCTION--?