欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

参照数组合并-php 二维数组合并 以一个数组为参照,比它多的项删除,比它少的项增加,相同的增加

程序员文章站 2024-04-04 10:55:17
...
参照数组合并php数组合并

$a = array('01' => array('count'=>1, 'amount'=>100,'cesgu'=>33),
'02' => array('count'=>2, 'amount'=>200),
'03' => array('count'=>3, 'amount'=>250) );
$b = array('01' => array('count'=>4, 'amount'=>300),
'02' => array('count'=> 5, 'amount'=>400));

以$a 为参照
输出Array ( [01] => Array ( [count] => 5 [amount] => 400 [cesgu] => 33 ) [02] => Array ( [count] => 7 [amount] => 600 )
[03] => Array ( [count] => 3 [amount] => 250 ) )

如果以$b为参照的话
输出Array ( [01] => Array ( [count] => 5 [amount] => 400 [cesgu] => 33 ) [02] => Array ( [count] => 7 [amount] => 600 )
请教下大家,