我正在尝试构建我的网站页面的嵌套数组。我已经有一个递归数组来嵌套基于父ID的结构。我想为每个后续数组添加一个键,该数组是页面的url。该网址将根据细分动态构建。
我的网页数组如下所示:
Array
(
[0] => Array
(
[title] => Homepage
[url_title] => homepage
[parent] =>
[pages] => Array
(
[0] => Array
(
[title] => About
[url_title] => about
[parent] => 1
[pages] =>
[_id] => 2
)
[1] => Array
(
[title] => Blog
[url_title] => blog
[parent] => 1
[pages] => Array
(
[0] => Array
(
[title] => Archives
[url_title] => archives
[parent] => 3
[pages] =>
[_id] => 4
)
)
[_id] => 3
)
)
[_id] => 1
)
)
我能够编写另一个遍历数组的递归函数,并创建另一个路径数组,如:
Array
(
[1] => '/homepage',
[2] => '/homepage/about',
[3] => '/homepage/blog',
[4] => '/homepage/blog/archives',
)
对于我的模板引擎,虽然我希望将这些值包含在嵌套数组中。