note 12875 deleted from function.usort by irchtml
| From: | irchtml@php.net | Date: | Mon, 08 Mar 2004 10:50:47 +0000 |
| Subject: | note 12875 deleted from function.usort by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-66427@lists.php.net to get a copy of this message | ||
Note Submitter: reiffer(at)kph.uni-mainz.de
----
This date-sort beats derek@luddite.net's date-sort by 25%.
If you like to use it, adjust $a[1]
and $b[1] to where your date is stored.
<? function data_sort($a,$b) {
if ($a[1] == $b[1]) { return 0;}
list($ayes,$ares) = split(" ",$a[1]);
// $a[1] = "15-02-2001 15:13:22";
list($byes,$bres) = split(" ",$b[1]);
list($aday,$amon,$ayear)= split("-",$ayes);
list($bday,$bmon,$byear)= split("-",$byes);
if ($ayear > $byear) {
return 1;
} elseif ($ayear < $byear) {
return -1;
} elseif ($amon > $bmon) {
return 1;
} elseif ($amon < $bmon) {
return -1;
} elseif ($aday > $bday) {
return 1;
} elseif ($aday < $bday) {
return -1;
} else {
list($ahou,$amin,$asec) = split(":",$ares);
list($bhou,$bmin,$bsec) = split(":",$bres);
if ($ahou > $bhou) {
return 1;
} elseif ($ahou < $bhou) {
return -1;
} elseif ($amin > $bmin) {
return 1;
} elseif ($amin < $bmin) {
return -1;
} else {
return ($asec > $bsec) ? -1 : 1;
}
}
} ?>