如何重新排列数组

时间:2014-09-24 12:26:44

标签: php arrays arraylist multidimensional-array

我正在使用php编写代码并且我一度陷入困境如果您知道任何解决方案,那么请给我回答。我有一个数组如下:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [Client] => Array
                        (
                            [id] => 64
                            [firstname] => abc
                            [lastname] => def
                            [email] => abc@gmail.com
                        )

                )

            [1] => Array
                (
                    [Client] => Array
                        (
                            [id] => 109
                            [firstname] => Sandip
                            [lastname] => Shah
                            [email] => abc223@gmail.com
                        )

                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [Client] => Array
                        (
                            [id] => 120
                            [firstname] => Vandana
                            [lastname] => Mathur
                            [email] => v@gmail.com
                        )

                )


        )

    [2] => Array
        (
            [0] => Array
                (
                    [Client] => Array
                        (
                            [id] => 113
                            [firstname] => Raj
                            [lastname] => Kumar
                            [email] => raj@gmail.com
                        )

                )

        )

)

现在我想要的最终数组如下: 使用数组php函数是否有可能使用以下方式?

Array
(
            [0] => Array
                (
                    [Client] => Array
                        (
                                [id] => 64
                                [firstname] => abc
                                [lastname] => def
                                [email] => abc@gmail.com
                        )

                )

            [1] => Array
                (
                    [Client] => Array
                        (
                            [id] => 109
                            [firstname] => Sandip
                            [lastname] => Shah
                            [email] => abc223@gmail.com
                        )

                )


            [2] => Array
                (
                    [Client] => Array
                        (
                            [id] => 120
                            [firstname] => Vandana
                            [lastname] => Mathur
                            [email] => v@gmail.com
                        )

                )

            [3] => Array
                (
                    [Client] => Array
                        (
                            [id] => 113
                            [firstname] => Raj
                            [lastname] => Kumar
                            [email] => raj@gmail.com
                        )

                )

)

1 个答案:

答案 0 :(得分:5)

那么,你只想合并深度2的所有数组?

很简单:展开大数组(通过call_user_func_array)并合并其内容:

$newArray = call_user_func_array('array_merge', $array);