I agree with other posters that you're doing it right already. However, in situations like these you could could try converting the $grade
to a value that could be used as an index in an associative array, not unlike what @ghostdog74 tried to do above.
$gradeindex = (int)$grade / 10; // 10 since we want 10-19 = 1, etc..
$gradenames = array('10' => 'A+', '9' => 'A', '8' => B, ..... );
However, since so many of them are identical, I'd probably use a switch()
$gradeindex = (int)$grade / 10; // 10 since we want 10-19 = 1, etc..
switch ($gradeindex) {
case 10:
case 9:
$gradename = 'A';
break;
case 8:
$gradename = 'B';
break;
case 7:
$gradename = 'C';
break;
default:
$gradename = 'Failed';
}
echo $gradename;
But as already said, you're basically best of with your current if
statement.