I have a bunch of dates in the form: MM-DD-YYYY in an array and I want to sort them and display them in descending order. I have tried the usort() function below and it's not working. Can anyone help me out here?
$menu_item = array(); $menu_item[] = "12-04-2003"; $menu_item[] = "11-19-2003"; $menu_item[] = "01-04-2004"; $menu_item[] = "12-24-2003"; $menu_item[] = "08-13-1982"; // sorting function function date_file_sort($a, $b) { $a = strtotime($a); $b = strtotime($b); return strcmp($a, $b); } usort($menu_item, 'date_file_sort'); // output results for($x = 0; $x < count($menu_item); $x++) { echo $menu_item[$x]."<br>"; } Here are the the results I get: 01-04-2004 08-13-1982 12-04-2003 11-19-2003 12-24-2003 Anyone know why these results seem totally random? Please help. Thanks, Matt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php