duang8642 2017-01-22 11:56 采纳率: 0%
浏览 150
已采纳

PHP:获取变量中的最高和最低值

Is their any way to get the highest and lowest value among variables?

example is that i have this variables

$val1 = 10
 $val2 = 20
 $val3 = 30
 $val4 = 40
 $val5 = 50

and among this variable i want to display or put to another variable the variable that has the highest and lowest value. just like below.

$highval = $val5; 
$lowval = $val1;

$val5 in $highval coz it has the value of 50 and $val1 in $lowval coz it has the value of 10 .

thanks

  • 写回答

3条回答 默认 最新

  • dtgj8529 2017-01-22 12:01
    关注

    When you are comparing a list of values, it's the best to store them in an array.

    Try this:

    $val1 = 10;
    $val2 = 20;
    $val3 = 30;
    $val4 = 40;
    $val5 = 50;
    
    $arr = compact('val1','val2','val3','val4','val5');  // Stores values in array $arr
    $highval = max($arr); // 50
    $lowval  = min($arr);  // 10
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的算法代码
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据