微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将数字键替换为默认的0-1-2等多维数组中的键

如何解决将数字键替换为默认的0-1-2等多维数组中的键

我有一个像这样的多维数组:

[stringKey] =>数组 ( [ 13 ] =>数组 ( [id] => 13 [名称] => smth [some_array] =>数组 ( [ 28 ] =>数组 ( [s_a_id] => 28 [名称] => smth [分支] =>数组 ( [0] =>数组 ( [b_id] => 1 [名称] => s_b_name_0 )

                                        [1] => Array
                                            (
                                                [bid] => 87
                                                [name] => s_b_name_1
                                            )

                        [**29**] => Array
                            (
                                [s_a_id] => **29**
                                [name] => smth1
                                [branches] => Array
                                    (
                                        [0] => Array
                                            (
                                                [b_id] => 8
                                                [name] => s_b_name_2
                                            )
                                     )
                            )

        )
        [**12**] => Array
            (
                [id] => **12**
                [name] => someName
                [some_array] => Array
                    (
                        [**12**] => Array
                            (
                                [s_a_id] => **12**
                                [name] => someString
                                [branches] => Array
                                    (
                                        [0] => Array
                                            (
                                                [b_id] => 3
                                                [name] => another_name
                                            )

                                        [1] => Array
                                            (
                                                [b_id] => 4
                                                [name] => another_value_name
                                            )
                                     )
                             )
                     )
             )
    )

我需要将数字数字键替换为认的有序键,例如0-1-2等:

[stringKey] =>数组 ( [ 0 ] =>数组 ( [id] => 13 [名称] => smth [some_array] =>数组 ( [ 0 ] =>数组 ( [s_a_id] => 28 [名称] => smth [分支] =>数组 ( [0] =>数组 ( [b_id] => 1 [名称] => s_b_name_0 )

                                        [1] => Array
                                            (
                                                [bid] => 87
                                                [name] => s_b_name_1
                                            )

                        [**1**] => Array
                            (
                                [s_a_id] => **29**
                                [name] => smth1
                                [branches] => Array
                                    (
                                        [0] => Array
                                            (
                                                [b_id] => 8
                                                [name] => s_b_name_2
                                            )
                                     )
                            )

        )
        [**1**] => Array
            (
                [id] => **12**
                [name] => someName
                [some_array] => Array
                    (
                        [**0**] => Array
                            (
                                [s_a_id] => **12**
                                [name] => someString
                                [branches] => Array
                                    (
                                        [0] => Array
                                            (
                                                [b_id] => 3
                                                [name] => another_name
                                            )

                                        [1] => Array
                                            (
                                                [b_id] => 4
                                                [name] => another_value_name
                                            )
                                     )
                             )
                     )
             )
    )

漂亮的格式:

current_array

needed_array

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。