質問は少し複雑です。めまいがする場合は入力しないでください^_^
array ( 0 => array ( 'id' => '10', 'title' => 'a',' type' => '1 ', 'bian'=>1'),
1 => 配列 ( 'id' => '10', 'title' => 'a',' type' => '1 ', 'bian'=>2),
2 => array ( 'id' => '11', 'title' => 'b','type' => '2', 'bian'=>1'),
3 => 配列 ( 'id' => '11', 'title' => 'c','type' => '2', 'bian'=>'2'),
)
type=1 の場合、同じ ID の重複が削除され、key は ID になります。 type=2 の場合、KEY は id_bian になります。 、そして最終的に次の array
array ( 0 => array ( '10' => '', '11_1' => '','11_2' => ''),) 次に、それを次の array
array ( 0 => array ( '10' => '1','11_2' => '1'),
1 => array ( ' 10' => '1',' 11_2' => '1')、
2 => 配列 ('11_1' => '1'、'11_2' => '1')、
3 => array ( ' 10' => '2','11_2' => '1'),
)
最後に
array ( 0 => array ( '10' => '1', '11_1'=> '','11_2' => '1'),
1 => 配列 ( '10' => '1', '11_1 => ', 11_2' = > '1'),
2 => 配列 ( '10' => ', '11_2' = > '1')、
3 => 配列 ('10' => '2'、'11_1' => ''、'11_2' => '1')、
)
----- -解決策---------
$a = array (<br /> 0 => array ( 'id' => '10', 'title' => 'a','type' => '1', 'bian'=>'1'), <br /> 1 => array ( 'id' => '10', 'title' => 'a','type' => '1', 'bian'=>'2'), <br /> 2 => array ( 'id' => '11', 'title' => 'b','type' => '2', 'bian'=>'1'),<br /> 3 => array ( 'id' => '11', 'title' => 'c','type' => '2', 'bian'=>'2'), <br />);<br />$b = array (<br /> 0 => array ( '10' => '1','11_2' => '1'), <br /> 1 => array ( '10' => '1','11_2' => '1'),<br /> 2 => array ( '11_1' => '1','11_2' => '1'),<br /> 3 => array ( '10' => '2','11_2' => '1'), <br />);<br />$t = array();<br />foreach($a as $item) {<br /> if($item['type'] == '1') {<br /> $t[$item['id']] = '';<br /> }else $t[$item['id'].'_'.$item['bian']] = '';<br />}<br />$c = array();<br />foreach($b as $v) {<br /> $r = array();<br /> foreach($t as $k=>$n) $r[$k] = @$v[$k];<br /> $c[] = $r;<br />}<br />print_r($c);
Array<br />(<br /> [0] => Array<br /> (<br /> [10] => 1<br /> [11_1] => <br /> [11_2] => 1<br /> )<br /><br /> [1] => Array<br /> (<br /> [10] => 1<br /> [11_1] => <br /> [11_2] => 1<br /> )<br /><br /> [2] => Array<br /> (<br /> [10] => <br /> [11_1] => 1<br /> [11_2] => 1<br /> )<br /><br /> [3] => Array<br /> (<br /> [10] => 2<br /> [11_1] => <br /> [11_2] => 1<br /> )<br /><br />)<br /><br />