name = $a1; $this->math = $a2; $this->english = $a3; } }// end class // 設定 stu物件變數陣列///////////////////////////////////////////////////// $avgmath =0; $avgenglish =0; if(isset($_POST['stuname'])){ foreach($_POST['stuname'] as $i=>$v){ $stu[$i] = new student($_POST['stuname'][$i],$_POST['math'][$i],$_POST['english'][$i]); }// end foreach //////計算全班數學,英文平均////////////////////////////////// $temp1=0; $temp2=0; foreach($stu as $i=>$v){ $temp1 += $stu[$i]->math; $temp2 += $stu[$i]->english; } $avgmath =$temp1/count($stu); $avgenglish =$temp2/count($stu); //////更新最新的input text 數學,英文輸入數值//////////////////////////////// }// end if(isset()) ?> 範例12-6

計算各科全班平均成績