[ create a new paste ] login | about

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

balajimca - PHP, pasted on Dec 3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
$array = array("2011-September_38","2011-June_4","2009-May_3","2009-May_45","2010-March_2","2010-November_9","2011-December_29","2010-March_19");
function yearmonthCompare($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, "yearmonthCompare");
foreach($array as $sorter)
{
$ids[] = explode("_",$sorter);
}
print_r($ids);

?>


Output:
Array
(
    [0] => Array
        (
            [0] => 2009-May
            [1] => 3
        )

    [1] => Array
        (
            [0] => 2009-May
            [1] => 45
        )

    [2] => Array
        (
            [0] => 2010-March
            [1] => 19
        )

    [3] => Array
        (
            [0] => 2010-March
            [1] => 2
        )

    [4] => Array
        (
            [0] => 2010-November
            [1] => 9
        )

    [5] => Array
        (
            [0] => 2011-June
            [1] => 4
        )

    [6] => Array
        (
            [0] => 2011-September
            [1] => 38
        )

    [7] => Array
        (
            [0] => 2011-December
            [1] => 29
        )

)


Create a new paste based on this one


Comments: