【发布时间】:2012-01-16 13:58:04
【问题描述】:
我很惊讶在 SO(或互联网上的其他地方)没有找到答案。它涉及一个嵌套缩进列表,我想根据缩进级别将其转换为多维数组。
举个例子,下面是一些示例输入:
Home
Products
Product 1
Product 1 Images
Product 2
Product 2 Images
Where to Buy
About Us
Meet the Team
Careers
Contact Us
理想情况下,我想将其输入一些(递归?)函数并获得以下输出:
array(
'Home' => array(),
'Products' => array(
'Product 1' => array(
'Product 1 Images' => array(),
),
'Product 2' => array(
'Product 2 Images' => array(),
),
'Where to Buy' => array(),
),
'About Us' => array(
'Meet the Team' => array(),
'Careers' => array(),
),
'Contact Us' => array(),
);
我对执行此类任务所需的逻辑感到困惑,因此我们将不胜感激。
【问题讨论】:
-
列表如何缩进,制表符 ||空格 || html ...
-
似乎 indent 方法可以(例如作为字符串)传递给构建这个数组数组的函数。
标签: php