note 25877 added to function.strtotime
| From: | ravi at theassistants dot com | Date: | Wed, 09 Oct 2002 18:28:45 +0000 |
| Subject: | note 25877 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37859@lists.php.net to get a copy of this message | ||
I had trouble with the above examples using this function to sort a MYSQL array and found that usort
was a better choice. The below example sorts a text column which may contain a date using the
strtotime function.
function sortbyorderdate($a, $b) {
if (empty($a["order_date"])) return -1;
if (empty($b["order_date"])) return 1;
return strcmp(strtotime($a["order_date"]), strtotime($b["order_date"]));
}
while ($rows[] = mysql_fetch_array($result)) {}
usort($rows, "sortbyorderdate");
--
http://www.php.net/manual/en/function.strtotime.php
http://master.php.net/manage/user-notes.php?action=edit+25877
http://master.php.net/manage/user-notes.php?action=delete+25877
http://master.php.net/manage/user-notes.php?action=reject+25877