Home  >  Q&A  >  body text

Use php to calculate level

20170530161608_365.png

<?php
    $aaa = "67";
    $bbb = "98";
    $ccc = "43";
    ?>
<table class="auto-style1" style="width: 28%; height: 134px">
    <tr>
        <td class="auto-style2">姓名</td>
        <td class="auto-style2">成绩</td>
        <td class="auto-style2">等级</td>
    </tr>
    <tr>
        <td class="auto-style2">AAA</td>
        <td class="auto-style2"><?php
         echo $aaa;
 ?></td>
        <td class="auto-style2"></td>
    </tr>
    <tr>
        <td class="auto-style2">BBB</td>
        <td class="auto-style2"><?php
         echo $bbb;
 ?></td>
        <td class="auto-style2">&nbsp;</td>
    </tr>
    <tr>
        <td class="auto-style2">CCC</td>
        <td class="auto-style2"><?php
         echo $ccc;
 ?></td>
        <td class="auto-style2">&nbsp;</td>
    </tr>
</table>

How to achieve hierarchical cell ranking?


wanfuwuwanfuwu2720 days ago757

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-31 09:32:23

    <?php
    $list=array(
        array('name'=>'AAA','score'=>67,'dengji'=>0),
        array('name'=>'BBB','score'=>98,'dengji'=>0),
        array('name'=>'CCC','score'=>43,'dengji'=>0),
    );
    function cmp($a,$b){
        global $list;
        $a=$list[$a]['score'];
        $b=$list[$b]['score'];
        if($a>$b){
            return true;
        }
        return false;
    }
    uksort($list,'cmp');
    $list=array_values($list);
    echo '姓名|分数|名次<br>';
    foreach($list as $k=>$row){
        echo $row['name'].'|'.$row['score'].'|'.($k+1);
    }


    reply
    0
  • PHP中文网

    Ranking displayed from high to low

    PHP中文网 · 2017-05-31 09:41:11
  • phpcn_u2725

    phpcn_u27252017-05-31 09:31:42

    Achievements are judged on a range basis

    reply
    0
  • Cancelreply