Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@zarosh 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