switch
not working like that.
Since $value
is 0
which is falsy value.
$value <= 25
is true
, $value > 25 && $value <= 50
is false
, so $CompScore
will be 'fair'
.
For you code, use an if elseif else
flow will be more readable.
You could rewrite your code like below:
// from excellent to low
if ($value > 75) {
$CompScore = 'excellent';
} else if ($value > 50) {
$CompScore = 'good';
} else if ($value > 25) {
$CompScore = 'fair';
} else {
$CompScore = 'low';
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…