duanqi6274 2013-07-18 03:46
浏览 107
已采纳

函数中的PHP变量

I am trying to make a grading scales for a grouping of variables. I'm running in to a few problems and am completely brain dead at the moment. Could anyone possibly give me some help on how to accomplish this? Very much appreciated!

function ovr_grade($talent, $physical, $entertainment, $reputation, $overness) {
if ($talent || $physical || $entertainment || $reputation || $overness >= 90) {
return "Grade: A";
} elseif ($talent || $physical || $entertainment || $reputation || $overness >= 80) {
return "Grade: B";
} elseif ($talent || $physical || $entertainment || $reputation || $overness >= 70) {
return "Grade: C";
} elseif ($talent || $physical || $entertainment || $reputation || $overness >= 60) {
return "Grade: D";
} elseif ($talent || $physical || $entertainment || $reputation || $overness >= 50) {
return "Grade: E";
} elseif ($talent || $physical || $entertainment || $reputation || $overness <= 49) {
return "Grade: F";
} else {
return "N/A";
}
}

echo ovr_grade();
  • 写回答

8条回答 默认 最新

  • dqu94359 2013-07-18 04:10
    关注

    i aaprreciate "James Anderson" Answer so +1 him,but max() calculation can be reduced

    $grades=  max($talent,$physical,$entertainment,$reputation);
    
    if($grades>90)
    {
    return "Grade: A";
    } 
    elseif ($grades>80)
    {
    return "Grade: B";
    } 
    .
    .
    .
    .
    .
    .
    else 
    {
    return "N/A";
    }
    

    update:

    unfortunately i cant get deep in to your "comment" anyway , i think you need a general function that returns grade for each factor (eg:physical,entertainment ... )

    function  getGrades($factor)
    {
    
    $grades= $factor;
    
    if($grades>90)
    {
    return "Grade: A";
    } 
    elseif ($grades>80)
    {
    return "Grade: B";
    } 
    .
    .
    .
    .
    .
    .
    else 
    {
    return "N/A";
    }
    }
    

    and make call to get grade for each

    echo "Talent : " . getGrades($talent);
    echo "Physical : " . getGrades($physical);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分 合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd
  • ¥50 C# 使用DEVMOD设置打印机首选项
  • ¥15 麒麟V10 arm安装gdal
  • ¥20 OPENVPN连接问题
  • ¥15 flask实现搜索框访问数据库
  • ¥15 mrk3399刷完安卓11后投屏调试只能显示一个设备