note 24101 added to function.usort
| From: | simen at NO_SPAM_AT_ALLbleed dot no | Date: | Tue, 06 Aug 2002 17:16:03 +0000 |
| Subject: | note 24101 added to function.usort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-34409@lists.php.net to get a copy of this message | ||
To sort a list of objects either ascending (a) or descending (d) using key use the function below
for comparison.
function property_sort($oa, $ob) {
global $sort_key;
global $sort_dir;
$a = strtolower($oa->$sort_key);
$b = strtolower($ob->$sort_key);
if ($a == $b) {
return 0;
} else if (($a > $b && $sort_dir == "a") || ($a < $b && $sort_dir
== "d")) {
return 1;
} else {
return -1;
}
}
--
http://www.php.net/manual/en/function.usort.php
http://master.php.net/manage/user-notes.php?action=edit+24101
http://master.php.net/manage/user-notes.php?action=delete+24101
http://master.php.net/manage/user-notes.php?action=reject+24101