sorting arrays by months
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/5697759/array-sort-function-in-php">Array sort function in PHP</a>  </p>
</blockquote>



<p>I have an array like so</p>

<pre><code>Array
(
[May] =&gt; 10904
[Jan] =&gt; 9269
[Jun] =&gt; 3743
[Feb] =&gt; 3507
[Mar] =&gt; 6017
[Apr] =&gt; 4966
)
</code></pre>

<p>How can I sort them by months. Jan, Feb, Mar, etc...</p>

<p>I tried this with no luck.</p>

<pre><code>$ytdCommissions = array_flip($ytdCommissions);

usort($ytdCommissions,'monthCompare');
function monthCompare($a, $b)
{
    $months = array('JAN' =&gt; 1, 'FEB' =&gt;2,'MAR' =&gt; 3,'APR' =&gt; 4,'MAY' =&gt; 5,'JUN' =&gt; 6,'JULY' =&gt; 7,'AUG' =&gt; 8, 'SEP' =&gt; 9, 'OCT' =&gt; 10, 'NOV' =&gt; 11, 'DEC' =&gt; 12);
    if($a == $b)
    {
        return 0;
    }
    return ($months[$a] &gt; $months[$b]) ? 1 : -1;
}
</code></pre>

<p>Thanks!</p>
