关于数组合并的问题
原数组:
<br /> $args1 = Array(<br /> '0' => array(<br /> '0' => 'a',<br /> '1' => array(<br /> '0' => array ( 'col1' => 'A1', 'col2' => 0 )<br /> )<br /> ),<br /> '1' => array(<br /> '0' => 'b',<br /> '1' => array(<br /> '0' => array ( 'col1' => 'B1', 'col2' => 1 )<br /> )<br /> )<br /> );<br /> $args2 = Array(<br /> '0' => array(<br /> '0' => 'a',<br /> '1' => array(<br /> '0' => Array ( 'col1' => 'A2', 'col2' => 0 ), <br /> '1' => Array ( 'col1' => 'A3', 'col2' => 0 ) <br /> )<br /> )<br /> );<br />
<br /> Array(<br /> '0' => array(<br /> '0' => 'a',<br /> '1' => array(<br /> '0' => array ( 'col1' => 'A1', 'col2' => 0 ),<br /> '1' => Array ( 'col1' => 'A2', 'col2' => 0 ), <br /> '2' => Array ( 'col1' => 'A3', 'col2' => 0 ) <br /> )<br /> ),<br /> '1' => array(<br /> '0' => 'b',<br /> '1' => array(<br /> '0' => array ( 'col1' => 'B1', 'col2' => 1 )<br /> )<br /> )<br /> );<br />
$res = array();<br /> foreach($args1 as $item) $res[$item[0]] = $item;<br /> foreach($args2 as $item) $res[$item[0]][1] = array_merge($res[$item[0]][1], $item[1]);<br /> <br /> print_r(array_values($res));