$arr[] = array('id'=>22533,'teacher'=>1275,'year'=>'2020','coursetype'=>5,'teachhour'=>8);
$arr[] = array('id'=>22534,'teacher'=>1275,'year'=>'2019','coursetype'=>3,'teachhour'=>6);
$arr[] = array('id'=>22532,'teacher'=>1275,'year'=>'2019','coursetype'=>5,'teachhour'=>8);
$arr[] = array('id'=>22535,'teacher'=>1275,'year'=>'2019','coursetype'=>5,'teachhour'=>7);
$arr[] = array('id'=>22536,'teacher'=>1275,'year'=>'2019','coursetype'=>5,'teachhour'=>8);
//怎么判断当teacher year coursetype 相同时让teachhour相加变成一条数据
$paramArr=array();
foreach($arr as $key => $value){
foreach($arr as $k => $val){
if($val['teacher'] == $value['teacher'] && $val['year'] == $value['year'] && $val['coursetype'] == $value['coursetype']){
$KeyXiaoLL = $value['teacher'].'-'.$value['year'].'-'.$value['coursetype'];
@$paramArr[$KeyXiaoLL]['total_hour'] = $val['teachhour']+$paramArr[$KeyXiaoLL]['total_hour'];
unset($arr[$k]);
}
}
}
//最终数组 $ArrXiaoLL
$ArrXiaoLL = array();
foreach($paramArr as $key=>$val){
if($val['total_hour'] <= 0){
continue;
}
$param = explode('-',$key);
$param['teacher'] = $param[0];
$param['year'] = $param[1];
$param['coursetype'] = $param[2];
unset($param[0]);
unset($param[1]);
unset($param[2]);
if(is_array($param)){
$param['total_hour'] = $val['total_hour'];
}
$ArrXiaoLL[] = $param;
}
echo '<pre>';
print_r($ArrXiaoLL);
exit;