<?php //追加数组 array_merge_recursive()函数与array_merge()相同,可以将两个或多个数组合并在一起,形成一个联合的数组.两者之间的区别在于,当某个输入数组中的某个键己经存在于结果数组中时该函数会采取不同的处理方式.array_merge()会覆盖前面存在的键/值对,替换为当前输入数组中的键/值对,而array_merge_recursive()将把两个值合并在一起,形成一个新的数组,并以原有的键作为数组名。还有一个数组合并的形式,就是递归追加数组 $arr=array( '0'=>array( 'purchase_type'=>'1', //0 带入 1 带出 'app_id'=>'1234567890abcdef', //游戏类别 'out_aft_change'=>'110',//帐变余额 'time'=>'2016-01-21', //参与时间 'cash'=>'160',//帐变金额 ), '1'=>array( 'purchase_type'=>'1', //0 带入 1 带出 'app_id'=>'1234567890abcdef', //游戏类别 'out_aft_change'=>'130',//帐变余额 'time'=>'2016-01-22', //参与时间 'cash'=>'150',//帐变金额 ), '2'=>array( 'purchase_type'=>'1', //0 带入 1 带出 'app_id'=>'1234567890abcdef', //游戏类别 'out_aft_change'=>'150',//帐变余额 'time'=>'2016-01-20', //参与时间 'cash'=>'140',//帐变金额 ), ); $arr2=array( '0'=>array( 'purchase_type'=>'0', //0 带入 1 带出 'app_id'=>'1234567890abcdef', //游戏类别 'out_aft_change'=>'110',//帐变余额 'time'=>'2016-01-21', //参与时间 'cash'=>'160',//帐变金额 ), '1'=>array( 'purchase_type'=>'0', //0 带入 1 带出 'app_id'=>'1234567890abcdef', //游戏类别 'out_aft_change'=>'130',//帐变余额 'time'=>'2016-01-22', //参与时间 'cash'=>'150',//帐变金额 ), '2'=>array( 'purchase_type'=>'0', //0 带入 1 带出 'app_id'=>'1234567890abcdef', //游戏类别 'out_aft_change'=>'150',//帐变余额 'time'=>'2016-01-20', //参与时间 'cash'=>'140',//帐变金额 ), ); $new_arr=array(); $new_arr=array( '0'=>array( 'purchase_type'=>'1', //0 带入 1 带出 'app_id'=>'1234567890abcdef', //游戏类别 'out_aft_change'=>'110',//帐变余额 'time'=>'2016-01-21', //参与时间 'cash'=>'160',//帐变金额 ), '1'=>array( 'purchase_type'=>'1', //0 带入 1 带出 'app_id'=>'1234567890abcdef', //游戏类别 'out_aft_change'=>'130',//帐变余额 'time'=>'2016-01-22', //参与时间 'cash'=>'150',//帐变金额 ), '2'=>array( 'purchase_type'=>'1', //0 带入 1 带出 'app_id'=>'1234567890abcdef', //游戏类别 'out_aft_change'=>'150',//帐变余额 'time'=>'2016-01-20', //参与时间 'cash'=>'140',//帐变金额 ), '3'=>array( 'purchase_type'=>'0', //0 带入 1 带出 'app_id'=>'1234567890abcdef', //游戏类别 'out_aft_change'=>'110',//帐变余额 'time'=>'2016-01-21', //参与时间 'cash'=>'160',//帐变金额 ), '4'=>array( 'purchase_type'=>'0', //0 带入 1 带出 'app_id'=>'1234567890abcdef', //游戏类别 'out_aft_change'=>'130',//帐变余额 'time'=>'2016-01-22', //参与时间 'cash'=>'150',//帐变金额 ), '5'=>array( 'purchase_type'=>'0', //0 带入 1 带出 'app_id'=>'1234567890abcdef', //游戏类别 'out_aft_change'=>'150',//帐变余额 'time'=>'2016-01-20', //参与时间 'cash'=>'140',//帐变金额 ), ); echo '<pre>'; print_r(array_merge_recursive($arr, $arr2)); echo '</pre>'; ?>