note 12875 modified in function.usort by irc-html
| From: | irc-html@php.net | Date: | Mon, 31 Dec 2001 01:31:03 +0000 |
| Subject: | note 12875 modified in function.usort by irc-html | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-24001@lists.php.net to get a copy of this message | ||
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;
}
}
} ?>
--was--
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 == $b) { 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;
} elseif ($asec > $bsec) {
return 1;
} elseif ($asec < $bsec) {
return -1;
}
}
} ?>
http://www.php.net/manual/en/function.usort.php