math - Rank Average with PHP -


in excel there's function rank average (see documentation).

i wish same in php. looking online, find lot of ranking solutions, not lot of take duplicates account , when do, result not same excel giving me @ all. it's important though.

ideally, i'd need function requires score , array compare with, , give me rank it.

example actual date excel:

$array = array(5.80,6.00,6.00,5.60,3.20,3.00,3.60,5.70,3.60,1.90,5.00,5.80,3.00,3.80,5.00,3.00,6.00,5.70,5.00,4.90,4.20,3.60,5.00,4.90,4.90,3.00 3.30,4.80,4.60,4.10,4.70,6.00,3.30,4.30,4.30,3.00,3.10,6.00,1.90,3.80,5.00,2.00,2.80,3.00,4.20,3.00,5.50,6.00,5.00,5.00);  $score1 = 5.80; $score2 = 6.00;  $rank1 = rankavg($score1, $array); //should return 7.5 $rank2 = rankavg($score2, $array); //should return 3.5 

function rank_avg($value, $array, $order = 0) { // sort     if ($order) sort ($array); else rsort($array); // add item counting 1 0   array_unshift($array, $value+1);  // select indexes vith value   $keys = array_keys($array, $value);   if (count($keys) == 0) return null; // calculate rank   return array_sum($keys) / count($keys); }  echo rank_avg(25, array(20,23,25,27,29), 1); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -