Page 1 of 1

help with two dimensional array

Posted: Thu Feb 21, 2008 5:49 am
by gammaman
How would I take the following array and add up and average each student, then print them out after using asort(). (This is NOT a HW assignment, I am just having a lot of trouble understanding 2d arrays and how they work so I thought I would set up an example.

$Student = array ( array (92,100,91),
array(96,82,77),
array(60,80,70),
array(90,90,90) );

Re: help with two dimensional array

Posted: Thu Feb 21, 2008 6:03 am
by Kieran Huggins
foreach to loop through the outer array, then deal with the inner arrays:

Code: Select all

foreach($students as $student){
   echo array_sum($student)/count($student);
}