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条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c