小编Hac*_*cus的帖子

改善其他条件

如何使下面的代码更优雅?目前我必须手动添加每个条件.有没有办法可以检查$ total_points的值是否位于数组$ ranking_list的连续项之间?

function ym_rank(){
$ranking_list = array(0, 400, 1000, 2500, 5000, 10000, 15000, 25000, 40000, 60000, 100000);
    if($total_points >= $ranking_list[0] and $total_points < $ranking_list[1]){
        return '<h2>Rank 0 </h2><br>';
    }
    elseif ($total_points >= $ranking_list[1] and $total_points < $ranking_list[2]){
        return '<h2>Rank 1 </h2><br>';
    }
    .
    .
    .
    so on
}
Run Code Online (Sandbox Code Playgroud)

php if-statement

5
推荐指数
1
解决办法
103
查看次数

标签 统计

if-statement ×1

php ×1