V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
astome
V2EX  ›  PHP

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

  •  
  •   astome · 2016-08-02 16:20:27 +08:00 · 1940 次点击
    这是一个创建于 3062 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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
                                (
                                )
    
                        )
    
                )
    
        )
    

    )

    3 条回复    2016-08-03 22:38:18 +08:00
    astome
        1
    astome  
    OP
       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
        2
    hanyouchun66  
       2016-08-02 17:49:39 +08:00
    invoke
        3
    invoke  
       2016-08-03 22:38:18 +08:00
    foreach 然后递归不就可以了吗
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   960 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:27 · PVG 06:27 · LAX 14:27 · JFK 17:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.