我很惊讶在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(),
);
我对执行此任务所需的逻辑感到困惑,希望能得到帮助。