PHP upgrade grades
<p>I have two arrays; <code>$marks</code> and <code>$grades</code>. <code>$marks</code> contain mark scored by a student and <code>$grades</code> is obtained by looping through <code>$marks</code> using the following function.</p>

<pre><code> function convertMarkToGrade($mark)
    {
        if($mark&lt;21)
            return "D";
        else if($mark&lt;33)
            return "C";
        else if($mark&lt;41)
            return "B";
        else if($mark&lt;=50)
            return "A";
    }
</code></pre>

<p>The problem is i want to upgrade the smallest and second smallest grades in <code>$grades</code> array using the following criteria</p>

<ol>
<li><p>Upscaling is done from lowest grade to next higher grade and so on ie B to A, C to B etc</p></li>
<li><p>In case of tie in Grades the grade with highest mark is upgraded.</p></li>
</ol>

<p>For example:<br>
Let <code>$marks</code> be <code>array(25,43,36,16,28)</code>. So we get <code>$grades</code> as <code>array("C","A","B","D","C")</code>. i want to generate a <code>$upgraded_grades =array("C","A","B","C","B")</code> ie the D grade (the smallest grade) is upgraded and the C grade(second smallest grade but with maximum marks) is also upgraded.</p>

<p>How can I do it in php?</p>
