Reputation: 1078
I'm looking to take a string such as
"/test/uri/to/heaven"
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.
Upvotes: 3
Views: 1583
Reputation: 11215
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);
Output:
array(1) {
["test"]=>
array(1) {
["uri"]=>
array(1) {
["to"]=>
array(1) {
["heaven"]=>
array(0) {
}
}
}
}
}
Upvotes: 5