Possible Duplicate:
Sort an array of dates using usort() and sort() functions by the timestamp converted by mktime()
I'm trying to sort an array of dates using sort() and usort() only - without using mktime(). I'm trying to compare month, day and year, but can not get the correct result, plus it gives me a bunch of warnings. Will appreciate any help.
$dates = array ('10-10-2003', '2-17-2002', '2-16-2003','1-01-2005', '10-10-2004' );
function toTime($date) {
return sort ($date, SORT_STRING);
}
function sortByTime($a, $b) {
$a = toTime($a);
$b = toTime($b);
if($a == $b) {
return 0;
}
return $a < $b ? -1 : 1 ;
}
usort($dates, 'sortByTime');
print_r($dates);
Thank you so much.