Blogger Information
Blog 19
fans 0
comment 0
visits 13204
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
函数、三元、if条件
王浩
Original
508 people have browsed it
  1. 作业:
  2. 1、函数练习
  3. 2、三元
  4. 3if语句
  5. 4、条件
  1. // 三元运算符
  2. function fun1($a){
  3. $b = $a ? "a有值" : "a无值";
  4. return $b;
  5. }
  6. echo fun1(1); // 输出a有值
  7. echo "<br/>";
  8. echo fun1(0); // 输出a无值
  9. echo "<br/>";
  10. // if判断条件
  11. function fun2($a){
  12. if(!is_numeric($a)){
  13. return ["code"=>-1,"msg"=>"参数不为数值"];
  14. }
  15. if($a > 100){
  16. return ["code"=>-1,"msg"=>"参数范围不正确"];
  17. }else if($a > 80){
  18. return ["code"=>0,"msg"=>"成绩优秀"];
  19. }else if($a > 60){
  20. return ["code"=>0,"msg"=>"成绩及格"];
  21. }else{
  22. return ["code"=>0,"msg"=>"成绩不及格"];
  23. }
  24. }
  25. print_r(fun2(100)); //输出Array ( [code] => 0 [msg] => 成绩优秀 )
  26. echo fun2(101)['msg']; //参数范围不正确
  27. echo fun2(85)['msg']; //成绩优秀
  28. echo fun2(75)['msg']; //成绩及格
  29. echo fun2(35)['msg']; //成绩不及格
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post