<?php $input = ['dir2', 'dir2_1', 'dir2_1_1']; $output = []; foreach (array_reverse($input) as $value) { $output = [$value => $output]; } var_dump($output);
You have javascript disabled. You will not be able to edit any code.