note 25878 deleted from function.array-multisort by aidan
| From: | aidan@php.net | Date: | Sun, 03 Oct 2004 10:57:37 +0000 |
| Subject: | note 25878 deleted from function.array-multisort by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77805@lists.php.net to get a copy of this message | ||
Note Submitter: ravi at theassistants dot com
----
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.
<?php
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");
?>