Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
作业:
1、函数练习
2、三元
3、if语句
4、条件
// 三元运算符
function fun1($a){
$b = $a ? "a有值" : "a无值";
return $b;
}
echo fun1(1); // 输出a有值
echo "<br/>";
echo fun1(0); // 输出a无值
echo "<br/>";
// if判断条件
function fun2($a){
if(!is_numeric($a)){
return ["code"=>-1,"msg"=>"参数不为数值"];
}
if($a > 100){
return ["code"=>-1,"msg"=>"参数范围不正确"];
}else if($a > 80){
return ["code"=>0,"msg"=>"成绩优秀"];
}else if($a > 60){
return ["code"=>0,"msg"=>"成绩及格"];
}else{
return ["code"=>0,"msg"=>"成绩不及格"];
}
}
print_r(fun2(100)); //输出Array ( [code] => 0 [msg] => 成绩优秀 )
echo fun2(101)['msg']; //参数范围不正确
echo fun2(85)['msg']; //成绩优秀
echo fun2(75)['msg']; //成绩及格
echo fun2(35)['msg']; //成绩不及格