note 24101 deleted from function.usort by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 09:03:24 +0000 |
| Subject: | note 24101 deleted from function.usort by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196863@lists.php.net to get a copy of this message | ||
Note Submitter: simen at NO_SPAM_AT_ALLbleed dot no
----
To sort a list of objects either ascending (a) or descending (d) using key use the function below
for comparison.
<?php
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;
}
}
?>