我正在寻找一个字符串,例如
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.
这是一个快速的非递归黑客:
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);
输出:
array(1) {
["test"]=>
array(1) {
["uri"]=>
array(1) {
["to"]=>
array(1) {
["heaven"]=>
array(0) {
}
}
}
}
}
这篇关于包含路径作为多维数组的字符串的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Zend 中的动作视图助手 - 解决方法?Action View Helper in Zend - Work around?(Zend 中的动作视图助手 - 解决方法?)
这是将 URI 与 PHP 中用于 MVC 的类/方法匹配的好方Is this a good way to match URI to class/method in PHP for MVC(这是将 URI 与 PHP 中用于 MVC 的类/方法匹配的好方法吗)
我在哪里保存 Zend Framework 中的部分(视图),以便Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(视图),以
有一个网站的单一入口点.坏的?好的?没问题?Having a single entry point to a website. Bad? Good? Non-issue?(有一个网站的单一入口点.坏的?好的?没问题?)
MVC + 服务层在 Zend 或 PHP 中常见吗?Is MVC + Service Layer common in zend or PHP?(MVC + 服务层在 Zend 或 PHP 中常见吗?)
PHP MVC 方法中的 Hello World 示例Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)