<?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));
You have javascript disabled. You will not be able to edit any code.