一个无限分类的数组能不能组合成一个 list 的二维数组,我好做循环

2016-08-02 16:20:27 +08:00
 astome

Array ( [0] => Array ( [id] => 1 [name] => --A [parent_id] => 0 [children] => Array ( [3] => Array ( [id] => 3 [name] => ----a [parent_id] => 1 [level] => 2 [children] => Array ( [4] => Array ( [id] => 4 [name] => ------aa [parent_id] => 3 [level] => 3 [children] => Array ( [6] => Array ( [id] => 6 [name] => --------aaa [parent_id] => 4 [level] => 4 [children] => Array ( )

                                                    )

                                            )

                                    )

                            )

                    )

            )

    )

[1] => Array
    (
        [id] => 2
        [name] => --B
        [parent_id] => 0
        [children] => Array
            (
                [5] => Array
                    (
                        [id] => 5
                        [name] => ----b
                        [parent_id] => 2
                        [level] => 2
                        [children] => Array
                            (
                            )

                    )

            )

    )

)

1922 次点击
所在节点    PHP
3 条回复
astome
2016-08-02 16:20:58 +08:00
Array
(
[0] => Array
(
[id] => 1
[name] => --A
[parent_id] => 0
[children] => Array
(
[3] => Array
(
[id] => 3
[name] => ----a
[parent_id] => 1
[level] => 2
[children] => Array
(
[4] => Array
(
[id] => 4
[name] => ------aa
[parent_id] => 3
[level] => 3
[children] => Array
(
[6] => Array
(
[id] => 6
[name] => --------aaa
[parent_id] => 4
[level] => 4
[children] => Array
(
)

)

)

)

)

)

)

)

[1] => Array
(
[id] => 2
[name] => --B
[parent_id] => 0
[children] => Array
(
[5] => Array
(
[id] => 5
[name] => ----b
[parent_id] => 2
[level] => 2
[children] => Array
(
)

)

)

)

)
hanyouchun66
2016-08-02 17:49:39 +08:00
invoke
2016-08-03 22:38:18 +08:00
foreach 然后递归不就可以了吗

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/296594

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX