合并多维数组逻辑

时间:2016-10-14 12:57:19

标签: php arrays multidimensional-array logic

我的数组

$array =

[0] => Array
    (
        [RevPReportPer] => 201606
        [AcctDb] => A
        [AcctNo] => 034
        [AcctBusName] => test
        [AcctDBAName] => test1
    )

[1] => Array
    (
        [RevPReportPer] => 201606
        [AcctDb] => A
        [AcctNo] => 034
        [AcctBusName] => test2
        [AcctDBAName] => test2
    )

[2] => Array
    (
        [RevPReportPer] => 201606
        [AcctDb] => A
        [AcctNo] => 036
        [AcctBusName] => COMPUTER
        [AcctDBAName] => computer2
    )

我的输出

[034] => Array
    (
        [RevPReportPer] => Array
            (
                [0] => 201606
                [1] => 201606
            )

        [AcctDb] => Array
            (
                [0] => A
                [1] => A
            )

        [AcctNo] => Array
            (
                [0] => 034
                [1] => 034
            )

        [AcctBusName] => Array
            (
                [0] => test
                [1] => test2
            )

        [AcctDBAName] => Array
            (
                [0] => test1
                [1] => test1
            )

    )

[036] => Array
    (
        [RevPReportPer] => 201606
        [AcctDb] => A
        [AcctNo] => 036
        [AcctBusName] => COMPUTER
        [AcctDBAName] => COMPUTER2

    )

我可以使用以下方式获得上述输出:

array_merge_recursive($array[0],$array[1],$array[2]);

我的问题如何将值动态传递给array_merge_recursive()

1 个答案:

答案 0 :(得分:5)

使用call_user_func_array()

将数组用作参数数组
$result = call_user_func_array('array_merge_recursive', $array);