title: Sorting PHP Array Keys in Month Order
body: <p>I am trying to get my function to display the months in the correct order, it gets June, July and May at the wrong position in the sequence.</p>
  
  <p>I would really appreciate some assistance on getting this to work correctly.</p>
  
  <pre><code>public function get_incident_data()
  {
      $all_incidents = $this-&gt;incidents_m-&gt;get_all_by_date();
  
      // Loop through and find &amp; replace month number with name
      $months_name = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
      $months_date = array('01','02','03','04','05','06','07','08','09','10','11','12');
  
      /**
      * Take the array and explode it to get 
      * the month number and replace it with the months name.
      * 
      * Output: [0] =&gt; Jan [1] =&gt; Feb [2] =&gt; Feb [3] =&gt; Feb [4] =&gt; Mar [5] =&gt; Apr ...
      */
      $months_are = array();
      foreach($all_incidents as $key =&gt; $value)
      {
          $date_bits = explode('-', $value['incident_date']);
          if($date_bits[1] != 00)
          {
              $months_are[] = str_replace($months_date, $months_name, $date_bits[1]); 
          }         
      }
  
      /**
      * Group and count all monthly incidents.
      */
      $result = array();
      foreach($months_are as $k =&gt; $v){  
          if(isset($result[$v])){
              $result[$v]++;
          }
          else {
              $result[$v] =1;
          }           
      }
  
      /** 
      * Currently Outputs: Array ( [Jan] =&gt; 1 [Feb] =&gt; 29 [Mar] =&gt; 66 [Apr] =&gt; 64 [Aug] =&gt; 1 [Sep] =&gt; 4 [Oct] =&gt; 2 [Nov] =&gt; 2 [Dec] =&gt; 1 [Jun] =&gt; 1 [Jul] =&gt; 1 [May] =&gt; 1 );
      *
      * Notice:- June, July &amp; May aren't in the right position.
      */
      print_r($result);
  }
  </code></pre>
  
  <p>Any Help is appreciated.</p>