4

My array

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

My output

[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

    )

I can get the above output using:

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

My question how to pass the values dynamically to array_merge_recursive().

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
Mohan
  • 85
  • 5
  • 6
    Check this link:- http://stackoverflow.com/questions/744145/passing-an-array-as-arguments-not-an-array-in-php – Ravi Hirani Oct 14 '16 at 13:04

1 Answers1

5

Use the array as an array of arguments using call_user_func_array():

$result = call_user_func_array('array_merge_recursive', $array);
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87