I have two arrays; $marks and $grades. $marks contain mark scored by a student and $grades is obtained by looping through $marks using the following function.
function convertMarkToGrade($mark)
{
if($mark<21)
return "D";
else if($mark<33)
return "C";
else if($mark<41)
return "B";
else if($mark<=50)
return "A";
}
The problem is i want to upgrade the smallest and second smallest grades in $grades array using the following criteria
-
Upscaling is done from lowest grade to next higher grade and so on ie B to A, C to B etc
-
In case of tie in Grades the grade with highest mark is upgraded.
For example:
Let $marks be array(25,43,36,16,28). So we get $grades as array("C","A","B","D","C"). i want to generate a $upgraded_grades =array("C","A","B","C","B") ie the D grade (the smallest grade) is upgraded and the C grade(second smallest grade but with maximum marks) is also upgraded.
How can I do it in php?
You can use Associative arrays. Here is a one of the method:
Edited: