当前位置:Gxlcms > PHP教程 > 参照数组合并-php二维数组合并以一个数组为参照,比它多的项删除,比它少的项增加,相同的增加

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

时间:2021-07-01 10:21:17 帮助过:23人阅读

参照数组合并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 )
请教下大家,

人气教程排行