我正在寻找能够将像下面的数组转换为输出结构树的最佳解决方案。
Array
(
[0] => Furniture/Chair
[1] => Furniture/Sofa/L Shaped
[2] => Furniture/Storage/Crockery Unit
[5] => Furniture/Sofa/1 Seater
[7] => Furniture/Sofa/2 Seater
[9] => Furniture/Sofa/3 Seater
[14] => Furniture/Storage/TV Unit
)
上面的数组是动态数组。我希望整个数组像下面的树一样转换。
- Furniture
Chair
Sofa
L Shaped
1 Seater
2 Seater
3 Seater
Storage
Crockery Unit
TV Unit
但主要的家具不是静态的,也是动态的,可能是n个术语
答案 0 :(得分:0)
您可以通过多种方式解决此问题。您可以解析每个数组并从值中创建一个低效的多维数组。或者您可以在PHP中构建一个实际的树。这是一篇关于PHP中的树的一篇很棒的SitePoint文章:http://www.sitepoint.com/data-structures-2/