php 两个二维数组重组新数组,数组下标不同
Array ( [0] => Array ( [PosNum] => 27025008 [start_time] => 20180328164929 [type] => 0 ) [1] => Array ( [PosNum] => 27065075 [start_time] => 20180328164939 [type] => 1 ) [2] => Array ( [PosNum] => 27065684 [start_time] => 20180329164918 [type] => 2 ) [3] => Array ( [PosNum] => 27065099 [start_time] => 20180329165556 [type] => 3 ) )
Array ( [5] => Array ( [StudentNumber] => 20116161 [PosNum] => 27025008 [judgmenttime] => 20180328164929 [type] => 0 ) [0] => Array ( [StudentNumber] => 3333号 [PosNum] => 27065075 [judgmenttime] => 20180328164939 [type] => 1 ) [4] => Array ( [StudentNumber] => 123654789 [PosNum] => 27065684 [judgmenttime] => 20180329164918 [type] => 2 ) [2] => Array ( [StudentNumber] => 232222222 [PosNum] => 27065099 [judgmenttime] => 20180329165556 [type] => 3 ) [1] => Array ( [StudentNumber] => 11111111 [PosNum] => 27065188 [judgmenttime] => 20180328165123 [type] => 0 ) [3] => Array ( [StudentNumber] => 3333333 [PosNum] => 27065066 [judgmenttime] => 20180328162058 [type] => 4 ) )
//重组数组 $arr1 = array(); foreach ($res as $k => $v) { //多的数组 foreach ($result as $ke => $va) { //少的数组为主 if ($v['PosNum'] == $va['PosNum']) { $arr1[$ke]['StudentNumber'] = $va['StudentNumber']; $arr1[$ke]['PosNum'] = $va['PosNum']; $arr1[$ke]['judgmenttime'] = $v['start_time']; // $arr1[$ke][$type[$v['type']]] = $v['start_time']; $arr1[$ke]['type'] =$v['type']; } } }