Note Submitter: g dot bell at NOSPAM dot managesys dot com dot au
----
/*
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;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.