Skip to content

Instantly share code, notes, and snippets.

@timw4mail
Created November 29, 2012 21:37
Show Gist options
  • Save timw4mail/4172083 to your computer and use it in GitHub Desktop.
Save timw4mail/4172083 to your computer and use it in GitHub Desktop.
Create directory structure in php
<?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);
}
}
}
<?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);
@zarosh
Copy link

zarosh commented Mar 13, 2018

call_user_func
Why this is used?and what is -- FUNCTION--?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment