我很驚訝沒有在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 ... – 2012-01-16 14:03:19
似乎可以將縮進方法(例如以字符串形式)傳遞給構建此數組數組的函數。 – Crontab 2012-01-16 14:07:28