Mohan Mohan - 1 month ago 18
PHP Question

Merge multidimensional array logic

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()
.

Answer

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

$result = call_user_func_array('array_merge_recursive', $array);
Comments