note 24101 modified in function.usort by danbrown

From: Date: Sun, 23 Jan 2011 16:31:31 +0000
Subject: note 24101 modified in function.usort by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176082@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. <?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; } } ?> --was-- 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://php.net/manual/en/function.usort.php

« previous php.notes (#176082) next »