Re: Sort Array by date

From: Date: Fri, 05 Dec 2003 00:44:32 +0000
Subject: Re: Sort Array by date
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-171928@lists.php.net to get a copy of this message
* Thus wrote Matt Palermo (webmaster@sweetphp.com): > 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); 12-04-2003 is not a valid date formate for strtotime(). http://www.gnu.org/manual/tar-1.12/html_chapter/tar_7.html Curt -- If eval() is the answer, you're almost certainly asking the wrong question. -- Rasmus Lerdorf, BDFL of PHP

« previous php.general (#171928) next »