[0] => dir2
[1] => dir2_1
[2] => dir2_1_1
...
array(
"dir2"=>array(
"dir2_1"=>array(
"dir2_1_1"=>array(...)
)
)
)
<?php
$input = ['dir2', 'dir2_1', 'dir2_1_1'];
function convert_array(array $input, array $output = []) {
if (empty($input)) {
return $output;
}
$value = array_pop($input);
return convert_array($input, [$value => $output]);
}
var_dump(convert_array($input));
<?php
$input = ['dir2', 'dir2_1', 'dir2_1_1'];
$output = [];
foreach (array_reverse($input) as $value) {
$output = [$value => $output];
}
var_dump($output);