note 25878 added to function.array-multisort
| From: | ravi at theassistants dot com | Date: | Wed, 09 Oct 2002 18:31:14 +0000 |
| Subject: | note 25878 added to function.array-multisort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37860@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.array-multisort.php
http://master.php.net/manage/user-notes.php?action=edit+25878
http://master.php.net/manage/user-notes.php?action=delete+25878
http://master.php.net/manage/user-notes.php?action=reject+25878