dongsui8162 2017-02-15 14:58
浏览 5
已采纳

根据它们的值显示7个变量

I have the following variables:

$points_maxbet = 0;
$points_netbet = 0;
$points_888 = 0;
$points_sportingbet = 0;
$points_betano = 0;
$points_unibet = 0;
$points_betfair = 0;

During the execution of the script their values get incremented by different values.

Example:

if ((mysqli_real_escape_string($con, $_POST['question_01'])) == 'A')
{
    $points_maxbet += 5;
    $points_netbet += 5;
    $points_888 += 5;
    $points_sportingbet += 5;
    $points_betano += 5;
    $points_unibet += 5;
    $points_betfair += 5;
}

After they pass trough all of the increments I want to display just 3 out of those 7 variables (based on their highest values) and display some HTML for each of them.

I tried something but it would only give me the highest value variable, not the following 2 as well.

Looked for a solution on SO and Google but couldn't find any.

Let me know if I need to provide more details.

  • 写回答

2条回答 默认 最新

  • doutuoben6908 2017-02-15 15:14
    关注

    I would say, put them in an array at the end, sort them and pick off the top 3 elements. Sort of like the following:

    <?php
        $array = array(
            'maxbet' => $points_maxbet,
            'netbet' => $points_netbet,
            'eighteighteight' => $points_eighteighteight,
            'sportingbet' => $points_sportingbet,
            'betano' => $points_betano,
            'unibet' => $points_unibet,
            'betfair' => $points_betfair);
        asort($array);
        $top3 = array_slice($array, -3);
    ?>
    

    Using this in html could be as simple as something like this (code not tested yet):

    <ol>
    <?php foreach($top3 as $key => $value): ?>
        <li><?php echo $key; ?> - <?php echo $value; ?></li>
    <?php endforeach; ?>
    </ol>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法