php - Sort array keys by date -


How can I sort this array by date using the key

  Array ([Jun '12] => 2037 [May '12] => 4615 [April '12] => 4175 [Mar '12] = & gt; 4548 [fir '12] = & gt; 2758 [Jan '12] = & gt; 3077 [Jul '12] = & gt; 0)   

I tried uksort with such a fortune with this callback function.

  function datediff ($ a, $ B) {strtotime ($ a); $ A = date ('u', strotomom ($ a)); $ B = date ('u', strotomom ($ b)); If ($ a == $ b) $ r = 0; Else $ r = ($ a & gt; $ b)? 1 1; Return $ R; }   

Any help is appreciated. Thanks!

"post-text" itemprop = "text">

You can create a custom mapping

  $ date_map = 5, "June" => 5, "June" => 2, "march" = & gt; 3, "April" = & gt; 4, "May" => 5, "June" = 6, "July" => 7, "August" = & gt; 8, "Sepen" = & gt; 9, "Oct." => 10, "November" => 11, "Dec" = & gt; 12); Function date_compare ($ a, $ b) {global $ date_map; $ A_month = $ date_map [substr ($ a, 0, 3)]; $ B_memth = $ date_map [substrack ($ b, 0, 3)]; If ($ a_month == $ b_month) 0; Return ($ a_month> $ b_month)? 1 1; }   

use date_compare with uksort

Comments