创建动态数组

时间:2015-04-03 12:55:19

标签: php arrays tree dynamic-arrays

我在使用数组创建树时遇到问题,我有一个这样的数组:

            Array
            (
                [area] => Gerencia Pais
                [id_area] => 1
                [id_area_padre] => 0
                [nivel] => 0
                [hijos] => Array
                    (
                        [0] => Array
                            (
                                [area] => Gerencia Corporativa Desarrollo de Negocios
                                [id_area] => 2
                                [id_area_padre] => 1
                                [nivel] => 1
                            )

                        [1] => Array
                            (
                                [area] => Despacho y Logística
                                [id_area] => 48
                                [id_area_padre] => 2
                                [nivel] => 2
                            )

                        [2] => Array
                            (
                                [area] => Atención al Cliente
                                [id_area] => 95
                                [id_area_padre] => 48
                                [nivel] => 3
                            )

但我需要这样的格式:

            Array
            (
                [area] => Gerencia Pais
                [id_area] => 1
                [id_area_padre] => 0
                [nivel] => 0
                [hijos] => Array
                    (
                        [0] => Array
                            (
                                [area] => Gerencia Corporativa Desarrollo de Negocios
                                [id_area] => 2
                                [id_area_padre] => 1
                                [nivel] => 1
                                [0] => Array
                                    (
                                        [area] => Despacho y Logística
                                        [id_area] => 48
                                        [id_area_padre] => 2
                                        [nivel] => 2
                                        [0] => Array
                                            (
                                                [area] => Atención al Cliente
                                                [id_area] => 95
                                                [id_area_padre] => 48
                                                [nivel] => 3
                                            )
                                    )
                                [1] => Array
                                    (
                                        [area] => Desarrollo y Tecnología
                                        [id_area] => 84
                                        [id_area_padre] => 2
                                        [nivel] => 2

                                    )
                            )

财产数量" nivel"深有界阵列。我可以做一个开关,但这是静态的,我需要自动创建这个树。

我希望你理解。任何答案都有帮助。感谢

0 个答案:

没有答案