note 63875 added to ref.array
| From: | g dot bell at NOSPAM dot managesys dot com dot au | Date: | Sun, 02 Apr 2006 22:57:34 +0000 |
| Subject: | note 63875 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107193@lists.php.net to get a copy of this message | ||
/*
function to give array of ranks. Handles ties.
input $arr is zero based array to be ranked
$order is the sorting order
'asc' (default) ranks smallest as 1
'desc' ranks largest as 1
output zero based array of ranks.
Ties (repeated values) given equal (integer) values
*/
function array_rank($arr,$order='asc') {
// $direction parameter
foreach($arr as $being_ranked) {
$t1 = $t2 = 0;
if ($order == 'asc') {
foreach ($arr as $checking) {
if ($checking > $being_ranked) continue;
if ($checking < $being_ranked) {
$t1++;
} else {
$t2++; // equal so increment tie counter
}
}
} elseif ($order == 'desc') {
foreach ($arr as $checking) {
if ($checking < $being_ranked) continue;
if ($checking > $being_ranked) {
$t1++;
} else {
$t2++; // equal so increment tie counter
}
}
}
$ranks[] = floor($t1 + ($t2 + 1) / 2);
}
return $ranks;
}
----
Server IP: 203.16.234.90
Probable Submitter: 203.45.88.30
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- http://master.php.net/note/edit/63875
Del: integrated -- http://master.php.net/note/delete/63875/integrated
Del: useless -- http://master.php.net/note/delete/63875/useless
Del: bad code -- http://master.php.net/note/delete/63875/bad+code
Del: spam -- http://master.php.net/note/delete/63875/spam
Del: non-english -- http://master.php.net/note/delete/63875/non-english
Del: in docs -- http://master.php.net/note/delete/63875/in+docs
Del: other reasons-- http://master.php.net/note/delete/63875
Reject -- http://master.php.net/note/reject/63875
Search -- http://master.php.net/manage/user-notes.php