我是一个新手,试图设计一个计算学生分数的应用程序。我正在尝试使用 OOP 简化我的工作,但我一直在这里遇到错误。这是我做的课:
class fun {
var $totalscore;
public function score($assignment,$cat,$exam){
return $totalscore = $assignment+$cat+$exam;
if($totalscore <=100 && $totalscore >=70){
return $grade = "A";
}
elseif($totalscore <=69 && $totalscore>=60){
return $grade = "B";
}
elseif($totalscore <=59 && $totalscore>=50){
return $grade = "C";
}
elseif($totalscore <=35 && $totalscore>=49){
return $grade = "D";
}
elseif($totalscore <=40 && $totalscore>=34){
return $grade = "E";
}
elseif($totalscore <=39 && $totalscore>=0){
return $grade = "F";
}
}
}
现在我试图在下面的其他 php 中调用变量我的意思是 $totalscore 和 $grade
if(isset($_POST['update'])){
$gnsa = $_POST['gnsa'];
$gnst =$_POST['gnst'];
$gnse =$_POST['gnse'];
$agidi =$_POST['matric'];
include ("class.php");
$fun = new fun;
$fun-> score($gnsa,$gnst,$gnse);
if($totalscore > 100){
echo "invalid score";
}
}