<?php
//$date = date('l dS \of F Y h:i:S A'); 
$dates[] = "Sunday 2nd of September 2004 12:03:02 am";
$dates[] = "Wednesday 14th of October 2002 10:22:01 pm";
$dates[] = "Saturday 19th of February 2005 08:14:02 am";
$dates[] = "Saturday 19th of February 2004 08:14:02 am";

$s SortDateByMonth($dates);
print_r($s);

/**
* function that sorts dates by month as string (like February and October)
* @name SortDateByMonth
* @param array $date_a the array of dates as strings
* @return array $sorted the sorted array or the original array if the month cannot be found
**/

function SortDateByMonth($date_a){
    
/**
    *@var $tmpdates the temporary array used for storing the dates with the months as numbers
    **/
    
$tmpdates;
    
    
/**
    *@var $months the array of months for looking up the number
    **/
    
$months = array('null','january','february','march','april','may','june','july','august','september','october','november','december');
    
    
/**
    *@var $month_loc the location of the month in the array after exploded; required to function
    **/
    
$month_loc = -1;
    
    
/**
    *@var $year_loc the location of the month in the array after exploded; optional.  used for additional sorting
    **/
    
$year_loc = -1;
    
/**
    *@var $sorted the sorted array to return
    **/
    
$sorted;
    
    
$test_date explode(' ',$date_a[0]);
    
$t_count count($test_date);
    for(
$j=0;$j<$t_count;$j++){
        
$tmp str_replace(',','',$test_date[$j]);// get rid of commas that might be touching the month
        
if(in_array(strtolower($tmp),$months)){
            
$month_loc $j;
        }
        if(
preg_match('/^\d\d\d\d$/',$tmp) && $tmp 2000){
            
$year_loc $j;
        }
    }
    if (
$month_loc==-1) return $date_a// can't find month, just return what you have
    
    
$count count($date_a);
    for(
$i=0;$i<$count;$i++){
        
$tmpdates[] = explode(' ',$date_a[$i]); // break it up
        
$month_sort[] = array_search(strtolower($tmpdates[$month_loc]),$months); // change month to number
        
if($year_loc!=-1){
            
$year_sort[] = $tmpdates[$year_loc];
        }
    }
    
$year_loc=-1?array_multisort($month_sort,SORT_ASC,$tmpdates):array_multisort($month_sort,SORT_ASC,$year_sort,SORT_ASC,$tmpdates);
    
// put them back together
    
for($i=0;$i<$count;$i++){
        
$sorted[] = implode(' ',$tmpdates[$i]);
    }
    return 
$sorted;
}

echo 
"\ndone";

?>