<?php
function ProcessPath($entry,$depth,&$current)
{
if($depth<count($entry))
{
$key = $entry[$depth];
if(!isset($current[$key]))$current[$key] = null;
ProcessPath($entry,$depth+1,$current[$key]);
}
}
$data = array(
array('path' => 'foo/bar/baz'),
array('path' => 'foo/pippo/bar/paperino'),
array('path' => 'paperino/pippo/bar/paperino'),
array('path' => 'foo/bar/baz/qux'),
array('path' => 'foo/bar'),
array('path' => 'foo/pippo/bar'),
array('path' => 'bar/baz/foo'),
array('path' => 'baz'),
array('path' => 'foo/pippo/bar/paperino'),
);
$result = null;
foreach($data as $path)
{
ProcessPath(explode("/",$path['path']),0,$result);
}
print_r($result);