Merge two arrays problem array 1:
$ Arr1 = Array ([0] => Array ([time] => 8: 00 [detail] => Array ([0] => Array ([caseid] => 31 [casename] => James) [1] => Array ([caseid] => 32 [casename] => Li Si) [2] => Array ([caseid] => 33 [casename] => Wang Wu ))) [1] => Array ([time] => 12: 00 [detail] => Array ([0] => Array ([caseid] => 32 [casename] => Li Si) [1] => Array ([caseid] => 33 [casename] => Wang Wu ))) [2] => Array ([time] => [detail] => Array ([0] => Array ([caseid] => 31 [casename] => John 3) [1] => Array ([caseid] => 32 [casename] => Li Si) [2] => Array ([caseid] => 33 [casename] => Wang Wu ))))
Array 2
$ Arr2 = Array ([0] => Array ([time] => 8: 00 [detail2] => Array ([0] => Array ([caseid] => 41 [casename] => Liu Bei ))) [1] => Array ([time] => 16: 00 [detail2] => Array ([0] => Array ([caseid] => 42 [casename] => Zhang Fei) [1] => Array ([caseid] => 43 [casename] => Zhao Yun ))) [2] => Array ([time] => 18:00 [detail2] => Array ([0] => Array ([caseid] => 43 [casename] => Zhao Yun) )) [2] => Array ([time] => 22: 00 [detail2] => Array ([0] => Array ([caseid] => 45 [casename] => mink) ))) after merging, the final array should be displayed as follows: [code = php] $ result = Array ([0] => Array ([time] => 8:00 [detail] => Array ([0] => Array ([caseid] => 31 [casename] => Michael Jacob) [1] => Array ([caseid] => 32 [casename] => Li Si) [2] => Array ([caseid] => 33 [casename] => Wang Wu )) [detail2] => Array ([0] => Array ([caseid] => 41 [casename] => Liu Bei ))) [1] => Array ([time] => 12: 00 [detail] => Array ([0] => Array ([caseid] => 32 [casename] => Li Si) [1] => Array ([caseid] => 33 [casename] => Wang Wu) [detail2] => Array ()) [2] => Array ([time] => 16: 00 [detail] => Array () [detail2] => Array ([0] => Array ([caseid] => 42 [casename] => Zhang Fei) [1] => Array ([caseid] => 43 [casename] => Zhao Yun ))) [3] => Array ([time] => [detail] => Array ([0] => Array ([caseid] => 31 [casename] => John 3) [1] => Array ([caseid] => 32 [casename] => Li Si) [2] => Array ([caseid] => 33 [casename] => Wang Wu )) [detail2] => Array ([0] => Array ([caseid] => 43 [casename] => Zhao Yun ))) [4] => Array ([time] => 22: 00 [detail] => Array () [detail2] => Array ([0] => Array ([caseid] => 45 [casename] => mink ))))
[/Code]
Reply to discussion (solution)
$ Arr1 = array (0 => array ('time' => '8: 00 ', 'detail' => array (0 => array ('caseid' => '31', 'casename' => 'Zhang San ',), 1 => array ('caseid' => '32', 'casename' => 'Lily',), 2 => array ('caseid' => '33 ', 'casename' => '王',), 1 => array ('time' => '12: 00 ', 'detail' => array (0 => array ('caseid' => '32', 'casename' => 'Lily ',), 1 => array ('caseid' => '33', 'casename' => 'Wang Wu ',),),), 2 => array ('time' => '18: 00', 'detail' => array (0 => array ('caseid' => '31 ', 'casename' => 'Zhang San',), 1 => array ('caseid' => '32', 'casename' => 'Li Si ',), 2 => array ('caseid' => '33', 'casename' => 'Wang Wu ',),),),); $ arr2 = array (0 => array ('time' => '8: 00 ', 'detail2' => array (0 => array ('caseid' => '41', 'casename' => 'Liu Bei ',),),), 1 => array ('time' => '16: 00', 'detail2' => array (0 => array ('caseid' => '42 ', 'casename' => 'Zhang Fei',), 1 => array ('caseid' => '43 ', 'casename' => 'Zhao Yun ',),),), 2 => array ('time' => '22: 00', 'detail2' => array (0 => array ('caseid' => '45 ', 'casename' => 'marker',); foreach ($ arr1 as $ item) $ a [$ item ['Time'] = $ item; foreach ($ arr2 as $ item) $ B [$ item ['Time'] = $ item; print_r (array_values (array_merge_recursive ($ a, $ B )));
Array ([0] => Array ([time] => Array ([0] => 8: 00 [1] => 8: 00) [detail] => Array ([0] => Array ([caseid] => 31 [casename] => Zhang San) [1] => Array ([caseid] => 32 [casename] => Li Si) [2] => Array ([caseid] => 33 [casename] => Wang Wu )) [detail2] => Array ([0] => Array ([caseid] => 41 [casename] => Liu Bei ))) [1] => Array ([time] => 12: 00 [detail] => Array ([0] => Array ([caseid] => 32 [casename] => Li Si) [1] => Array ([caseid] => 33 [casename] => Wang Wu ))) [2] => Array ([time] => [detail] => Array ([0] => Array ([caseid] => 31 [casename] => John 3) [1] => Array ([caseid] => 32 [casename] => Li Si) [2] => Array ([caseid] => 33 [casename] => Wang Wu ))) [3] => Array ([time] => 16: 00 [detail2] => Array ([0] => Array ([caseid] => 42 [casename] => Zhang Fei) [1] => Array ([caseid] => 43 [casename] => Zhao Yun ))) [4] => Array ([time] => 22: 00 [detail2] => Array ([0] => Array ([caseid] => 45 [casename] => mink) )))
Php provides rich functions
You should do it yourself
There is a problem with array 2. the subscript at and are both 2. change to 3.
'; $ Arr1 = array (0 => array ('time' => '8: 00 ', 'detail' => array (0 => array ('caseid' => '31', 'casename' => 'Zhang San ',), 1 => array ('caseid' => '32', 'casename' => 'Lily',), 2 => array ('caseid' => '33 ', 'casename' => '王',), 1 => array ('time' => '12: 00 ', 'detail' => array (0 => array ('caseid' => '32', 'casename' => 'Lily ',), 1 => array ('caseid' => '33', 'casename' => 'Wang Wu ',),),), 2 => array ('time' => '18: 00', 'detail' => array (0 => array ('caseid' => '31 ', 'casename' => 'Zhang San',), 1 => array ('caseid' => '32', 'casename' => 'Li Si ',), 2 => array ('caseid' => '33', 'casename' => 'Wang Wu ',),),),); $ arr2 = array (0 => array ('time' => '8: 00 ', 'detail2' => array (0 => array ('caseid' => '41', 'casename' => 'Liu Bei ',),),), 1 => array ('time' => '16: 00', 'detail2' => arra Y (0 => array ('caseid' => '42', 'casename' => 'Zhang Fei ',), 1 => array ('caseid' => '43 ', 'casename' => 'Zhao Yun ',),),), 2 => array ('time' => '18: 00', 'detail2' => array (0 => array ('caseid' => '43 ', 'casename' => 'Zhao Yun',), 3 => array ('time' => '22: 00 ', 'detail2' => array (0 => array ('caseid' => '45', 'casename' => 'marker ',),),),); $ result = array (); foreach ($ arr1 as $ row) {$ key = $ row [' Time']; $ row ['detail2'] = array (); $ result [$ key] = $ row;} foreach ($ arr2 as $ row) {$ key = $ row ['Time']; if (! Isset ($ result [$ key]) {$ result [$ key] = array ('time' => $ row ['Time'], 'detail' => array (), 'detail2' => $ row ['detail2']);} else {$ result [$ key] ['detail2'] = $ row ['detail2'] ;}} ksort ($ result, SORT_NUMERIC ); $ result = array_values ($ result); echo'';print_r($result);echo '
';?>
Array ([0] => Array ([time] => 8:00 [detail] => Array ([0] => Array ([caseid] => 31 [casename] => james) [1] => Array ([caseid] => 32 [casename] => Li Si) [2] => Array ([caseid] => 33 [casename] => Wang Wu )) [detail2] => Array ([0] => Array ([caseid] => 41 [casename] => Liu Bei ))) [1] => Array ([time] => 12: 00 [detail] => Array ([0] => Array ([caseid] => 32 [casename] => Li Si) [1] => Array ([caseid] => 33 [casename] => Wang Wu) [detail2] => Array ()) [2] => Array ([time] => 16: 00 [detail] => Array () [detail2] => Array ([0] => Array ([caseid] => 42 [casename] => Zhang Fei) [1] => Array ([caseid] => 43 [casename] => Zhao Yun ))) [3] => Array ([time] => [detail] => Array ([0] => Array ([caseid] => 31 [casename] => John 3) [1] => Array ([caseid] => 32 [casename] => Li Si) [2] => Array ([caseid] => 33 [casename] => Wang Wu )) [detail2] => Array ([0] => Array ([caseid] => 43 [casename] => Zhao Yun ))) [4] => Array ([time] => 22: 00 [detail] => Array () [detail2] => Array ([0] => Array ([caseid] => 45 [casename] => mink ))))
Thank you very much. you have done it yourself.