[ create a new paste ] login | about

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

balajimca - PHP, pasted on Dec 1:
<?php
$array = array("2011-September_38","2011-June_4","2011-November_9");
function monthCompare($a, $b) {
    $a = strtolower(substr($a,5,-3));
    $b = strtolower(substr($b,5,-3));
    echo    $a."\n";
    $months = array(
	'January'=> 1,
	'February'=> 2,
	'March'=>3,
	'April'=>4,
	'May'=>5,
	'June'=>6,
	'July'=>7,
	'August'=>8,
	'September'=>9,
	'October'=>10,
	'November'=>11,
	'December'=>12
 );
    if($a == $b)
        return 0;
    if(!isset($months[$a]) || !isset($months[$b]))
        return $a > $b;
    return ($months[$a] > $months[$b]) ? 1 : -1;
}
usort($array, "monthCompare");
print_r($array);
?>


Output:
1
2
3
4
5
6
7
8
9
10
jun
novembe
september
novembe
Array
(
    [0] => 2011-June_4
    [1] => 2011-November_9
    [2] => 2011-September_38
)


Create a new paste based on this one


Comments: