合并多维数组逻辑
Posted
技术标签:
【中文标题】合并多维数组逻辑【英文标题】:Merge multidimensional array logic 【发布时间】:2017-02-23 22:07:30 【问题描述】:我的数组
$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()
。
【问题讨论】:
查看此链接:- ***.com/questions/744145/… 【参考方案1】:使用 call_user_func_array()
将数组用作参数数组:
$result = call_user_func_array('array_merge_recursive', $array);
【讨论】:
非常感谢@AbraCadaver以上是关于合并多维数组逻辑的主要内容,如果未能解决你的问题,请参考以下文章