[ create a new paste ] login | about

Link: http://codepad.org/JELYk99G    [ raw code | output | fork ]

balajimca - PHP, pasted on Dec 2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
$array = array("2011-September_38","2011-June_4","2009-May_45","2010-November_9","2011-December_29","2010-March_19");
function monthCompare($a, $b) {
   $count = substr($a,strpos($a,'_'));
   $count =strlen($count);
   $count1 = substr($b,strpos($b,'_'));
   $count1 =strlen($count1);
   $da = strtotime(substr($a,0,-$count));
   $db = strtotime(substr($b,0,-$count1));
   return $da > $db;
}
usort($array, "monthCompare");
print_r($array);
?>


Output:
1
2
3
4
5
6
7
8
9
Array
(
    [0] => 2009-May_45
    [1] => 2010-March_19
    [2] => 2010-November_9
    [3] => 2011-June_4
    [4] => 2011-September_38
    [5] => 2011-December_29
)


Create a new paste based on this one


Comments: