Jump to content

[SOLVED] array help


Thethug

Recommended Posts

try this

<form method='post' action=''>
<?php
$average= 0;
$values = array('grades' => array_fill(0, 10, 0));
if(isset($_POST['grades'])){
$values = $_POST;
$grade=$_POST['grades'];
$total = 0;
foreach($grade as $grades){
	$total += $grades;
}
$average = $total/count($_POST["grades"]);
}

for($n=0;$n<10;$n++){
echo "Grade ".($n+1).":<input name=\"grades[$n]\" type=\"text\" value = \"{$values['grades'][$n]}\" />";
}
?>
<input type='Submit' name='Submit' value="Submit" />
</form>
<?php
echo getGrades($average);

function getGrades($grade){
if ($grade >= 89.5){//is A
	return 'A';
}elseif ($grade >= 79.5){
	return 'B';
}elseif($grade >= 69.5){
	return 'C';
}elseif ($grade >= 59.5){
	return 'D';
}
return 'F';
}


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.