Bulding on @preinheimer's answer, here is a version that will do a sequential sort if the name doesn't exist:
$data = array("Apr", "Mar", "Jan", "Feb", "ddd", "aaa", "ccc");
function monthCompare($a, $b) {
$a = strtolower($a);
$b = strtolower($b);
$months = array(
'jan' => 1,
'feb' => 2,
'mar' => 3,
'apr' => 4,
'may' => 5
);
if($a == $b)
return 0;
if(!isset($months[$a],$months[$b]))
return $a > $b;
return ($months[$a] > $months[$b]) ? 1 : -1;
}
usort($data, "monthCompare");
echo "<pre>";
print_r($data);
Returns:
Array
(
[0] => aaa
[1] => ccc
[2] => ddd
[3] => Jan
[4] => Feb
[5] => Mar
[6] => Apr
)
However - this highlights logic flaw with your question. You've asked that it be sorted by month sequence otherwise by alphabet. The problem with that is you haven't sufficiently defined the sort order in a way that can be reliabliy replicated. For example, using the above algorythm and the array "ddd", "aaa", "ccc", "Apr", "Mar", "Jan", "Feb" (ie, same elements) gives the result:
Array
(
[0] => aaa
[1] => Jan
[2] => Feb
[3] => Mar
[4] => Apr
[5] => ccc
[6] => ddd
)
Both answers are correct according to your request, so you need to define the sort requirement in more detail.