Tuesday, 15 January 2013

php - Sorting of array keys in which keys are labeled Apr 16-30, May 1-15 -


I got an array with the key of my group group

  $ array = [' Apr 1-15 '= & gt; [], '1-15 May' => [], 'Apr 16-30 = & gt; [],];  

I want to sort them out like this,

  $ array = ['Apr 1-15' = & gt; [], 'Apr 16-30 = & gt; [], '1-15 May' => [],];  

What I have done now:

  uksort ($ data, function ($ a, $ b) {$ a = explosion ('', $ A); $ b = Explosion ('', $ b); Back Strass CMP ($ a [0], $ b [0]);});  

But I still can not sort them correctly. Any help in deciding this? Thanks

Use ksort () to sort arrays:

  & lt ;? Php $ array = ['Apr 1-15' => [], '1-15 May' => [], 'Apr 16-30' = & gt; []]; Ksort ($ array); Print_r ($ array);  

The output will be:

  array ([1 April] => Hey () [Apr 16-30] => array () [May 1-15] = & gt; array ())  

No comments:

Post a Comment