I have one array stores grade names, with grade value as key and grade name as value:
$labels=array(1=>'Insufficient',2=>'Sufficient',3=>'Satisfactory',4=>'Good',5=>'Excellent' );
Then, there's another array stores all record of people who gained a grade, with user_id as key and grade value as value:
$grades = array( 123 = > 1, 456 => 5 , 789 = > 3);
Now I want to count the record under each grade-- grade-1 => 5 users, grade-2=>6 users
, in the form like this:
array(1=>5, 2=>6, 3=>2, 4=>2, 5=>1);
I tried this and got errors of Undefined offset:
$result = array();
for($i=1;$i<=5;++$i)
{
foreach($grades as $user_id=>$user_grade)
{
$result[$i] = ( $user_grade == $i ) ? $result[$i]+1 : $result[$i];
}
}
How to get an result array of counting how many user under each grade?