You are here

public static function PHPExcel_Calculation_Statistical::RANK in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Statistical.php \PHPExcel_Calculation_Statistical::RANK()

* RANK * * Returns the rank of a number in a list of numbers. * *

Parameters

number The number whose rank you want to find.: * @param array of number An array of, or a reference to, a list of numbers. * @param mixed Order to sort the values in the value set * @return float

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Statistical.php, line 2800

Class

PHPExcel_Calculation_Statistical
PHPExcel_Calculation_Statistical

Code

public static function RANK($value, $valueSet, $order = 0) {
  $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
  $valueSet = PHPExcel_Calculation_Functions::flattenArray($valueSet);
  $order = is_null($order) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($order);
  foreach ($valueSet as $key => $valueEntry) {
    if (!is_numeric($valueEntry)) {
      unset($valueSet[$key]);
    }
  }
  if ($order == 0) {
    rsort($valueSet, SORT_NUMERIC);
  }
  else {
    sort($valueSet, SORT_NUMERIC);
  }
  $pos = array_search($value, $valueSet);
  if ($pos === False) {
    return PHPExcel_Calculation_Functions::NA();
  }
  return ++$pos;
}