时间:2021-07-01 10:21:17 帮助过:15人阅读
$a = array ( 0 => array ( 'id' => '10', 'title' => 'a','type' => '1', 'bian'=>'1'), 1 => array ( 'id' => '10', 'title' => 'a','type' => '1', 'bian'=>'2'), 2 => array ( 'id' => '11', 'title' => 'b','type' => '2', 'bian'=>'1'), 3 => array ( 'id' => '11', 'title' => 'c','type' => '2', 'bian'=>'2'), );$b = array ( 0 => array ( '10' => '1','11_2' => '1'), 1 => array ( '10' => '1','11_2' => '1'), 2 => array ( '11_1' => '1','11_2' => '1'), 3 => array ( '10' => '2','11_2' => '1'), );$t = array();foreach($a as $item) { if($item['type'] == '1') { $t[$item['id']] = ''; }else $t[$item['id'].'_'.$item['bian']] = '';}$c = array();foreach($b as $v) { $r = array(); foreach($t as $k=>$n) $r[$k] = @$v[$k]; $c[] = $r;}print_r($c);
Array( [0] => Array ( [10] => 1 [11_1] => [11_2] => 1 ) [1] => Array ( [10] => 1 [11_1] => [11_2] => 1 ) [2] => Array ( [10] => [11_1] => 1 [11_2] => 1 ) [3] => Array ( [10] => 2 [11_1] => [11_2] => 1 ))
$a = array ( 0 => array ( 'id' => '10', 'title' => 'a','type' => '1', 'bian'=>'1'), 1 => array ( 'id' => '10', 'title' => 'a','type' => '1', 'bian'=>'2'), 2 => array ( 'id' => '11', 'title' => 'b','type' => '2', 'bian'=>'1'), 3 => array ( 'id' => '11', 'title' => 'c','type' => '2', 'bian'=>'2'), );$b = array ( 0 => array ( '10' => '1','11_2' => '1'), 1 => array ( '10' => '1','11_2' => '1'), 2 => array ( '11_1' => '1','11_2' => '1'), 3 => array ( '10' => '2','11_2' => '1'), );$t = array();foreach($a as $item) { if($item['type'] == '1') { $t[$item['id']] = ''; }else $t[$item['id'].'_'.$item['bian']] = '';}$c = array();foreach($b as $v) { $r = array(); foreach($t as $k=>$n) $r[$k] = @$v[$k]; $c[] = $r;}print_r($c);
Array( [0] => Array ( [10] => 1 [11_1] => [11_2] => 1 ) [1] => Array ( [10] => 1 [11_1] => [11_2] => 1 ) [2] => Array ( [10] => [11_1] => 1 [11_2] => 1 ) [3] => Array ( [10] => 2 [11_1] => [11_2] => 1 ))
不太明白你的意思
不太明白你的意思
$a = array ( 0 => array ( 'id' => '10', 'title' => 'a','type' => '1', 'bian'=>'1'), 1 => array ( 'id' => '10', 'title' => 'a','type' => '1', 'bian'=>'2'), 2 => array ( 'id' => '11', 'title' => 'b','type' => '2', 'bian'=>'1'), 3 => array ( 'id' => '11', 'title' => 'c','type' => '2', 'bian'=>'2'), );$b = array ( 0 => array ( '10' => '1','11_2' => '1'), 1 => array ( '10' => '1','11_2' => '1'), 2 => array ( '11_1' => '1','11_2' => '1'), 3 => array ( '10' => '2','11_2' => '1'), );$t = array();foreach($a as $item) { if($item['type'] == '1') { $t[$item['id']] = ''; }else $t[$item['id'].'_'.$item['bian']] = '';}$c = array();foreach($b as $v) { $r = array(); foreach($t as $k=>$n) $r[$k] = @$v[$k]; $c[] = $r;}print_r($c);
并没有遍历 $c 啊