I am working with 4 arrays, each array contains students last names and their test grades for 4 different tests. What I am trying to do is find the average For each student, calculate and display their average grade. How would I find Smiths average grade from all 4 arrays? I am very new to PHP so any directions would be useful. Thank you!
PHP:
$testOne = array (
'Smith'=> 98,
'Johnson' => 67,
);
$testTwo = array (
'Smith'=> 100,
'Johnson' => 85,
);
$testThree = array (
'Smith'=> 78,
'Johnson' => 92,
);
$testFour = array (
'Smith'=> 91,
'Johnson' => 88,
);
I found one way to get the average but can anyone tell me if there is a more efficient way? I created separate arrays for each student and then divided by the count.
$smith = array(98,100,91,75);
$johnson = array(67,88,85,81)
echo('Smiths average test score is ' . array_sum($smith) / 4);