数组合并不会在foreach php中工作

can anyone tell my why the $output array is always only the last $tmp array of the foreachloop.

im pulling hairs here..

private function create_dir_array($dirs) {
    $output = array();
    foreach ($dirs as $key => $path) {
        $path = split('/',$path);
        $tmp = array();
        $counter = count($path)-1;
        for($i = $counter; $i >= 0; $i--)
        {
            $tmp = array($path[$i] => $tmp);
        }
        $output = array_merge($output, $tmp);
    }
    print("<pre>".print_r($output,true)."</pre>");

}

if have this array

Array
(
    [0] => archive/folder1
    [1] => archive/folder1/subfolder1
    [2] => archive/folder2
    .....
)

and i want that array out of the given data may anyone has a better simpler idea for this?

Array
(
    [archive] => Array(
        [folder1] => Array(
            [subfolder1] => Array()
            )
        )
        [folder2] => Array(
         ......
)

Because you override it on every iteration in your loop:

for($i = $counter; $i >= 0; $i--)
{
    $tmp = array($path[$i] => $tmp);
}

Well it works just fine is i use array_merge_recursive. What now is totally logical to me.

still its a heck of code for actually not much.