A function isn't necessary for this at all. PHP's built-in associative arrays can handle it quite nicely.
I don't see how you've called the function, since a variable to pass as a grade isn't defined anywhere. I suggest sending it via GET:
Code:
<?php
$gradeMessages = array(
'A' => 'Your grade is excellent.',
'B' => 'Your grade is good.',
'C' => 'Your grade is fair.',
'D' => 'You are barely passing.',
'E' => 'You failed.'
);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Grade Meanings</title>
</head>
<body>
<div>
<h1><?php echo $gradeMessages[@$_GET['grade']]; ?></h1>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<label>
Grade:
<select>
<?php foreach(array_keys($gradeMessages) as $grade) { ?>
<option
value="<?php echo $grade; ?>"
<?php if($grade === @$_GET['grade']) echo 'selected="selected"'; ?>>
<?php echo $grade; ?>
</option>
<?php } ?>
</select>
</label>
<input type="submit" value="Submit">
</form>
</div>
</body>
</html>
Bookmarks