douhuang9886 2017-09-06 13:14
浏览 54
已采纳

坚持得到两个最小的几个变量

I'm pretty new to PHP, still learning, but I just cant get the solution.

I have 3 variables

$line1 = 5;
$line2 = 3;
$line3 = 7;

I need a hint on how to get the 2 lowest variables and IF the sum of those 2 variables is higher than the 3rd variable it should echo.

I'm guessing an if-else statement or switch, but im not sure.
But i'm mostly stuck on how to get the 2 minimums.

Anyone can help? Sorry, im still a noob xD

  • 写回答

1条回答 默认 最新

  • dongqigu0429 2017-09-06 13:18
    关注
    $all = [$line1, $line2, $line3];
    
    sort($all);
    
    if ($all[0] + $all[1] > $all[2]) {
        echo $all[2];
    }
    

    This should do.

    Next time you should atleast try before asking and show us what you have done beforehand. This is not a "Cant do it, can you do it for me please?" but rather "I have done this, can you help me fix it?" type.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?