- rand: documentation ( source)
<?php
//Intialize the input
$score=rand(50,100);
//Determine the Grade
//$grade= ($score>=90)?'A':(($score>=80)?'B':(($score>=70)?'C':(($score>=60)?'D':'F')));
if ($score >= 90) {
$grade = 'A';
}
elseif ($score >= 80) {
$grade = 'B';
}
elseif ($score >= 70) {
$grade = 'C';
}
elseif ($score >= 60) {
$grade = 'D';
} else {
$grade = 'F';
}
//Output the Results
echo "<h1>A score of $score = $grade</h1>";