views:

10

answers:

1

I'm looking to take a string such as

/var/www/vhosts

and turn it into a multi-dimensional, nested array such as:

array(
    'var'=>array(
        'www'=>array(
            'vhosts'=>array()            
        ),
    ),
);

Anyone got any pointers? I've had a look through Google and the search here, but I've not seen anything.

Thanks very much.

A: 

here is a quick non recursive hack:

$url = "/test/uri/to/heaven";
$parts = explode('/',$url);

$arr = array();
while($bottom = array_pop($parts)){

    $arr = array($bottom => $arr);
}
var_dump($arr);
ITroubs
my var_dump looks like this: array(1) { ["test"]=> array(1) { ["uri"]=> array(1) { ["to"]=> array(1) { ["heaven"]=> array(0) { } } } }}
ITroubs
This is great, thanks very much =)
atomicguava