You are here

public static function PHPExcel_Calculation_Statistical::MEDIAN in Loft Data Grids 7.2

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

* MEDIAN * * Returns the median of the given numbers. The median is the number in the middle of a set of numbers. * * Excel Function: * MEDIAN(value1[,value2[, ...]]) * * @access public * @category Statistical Functions *

Parameters

mixed $arg,... Data values: * @return float

File

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

Class

PHPExcel_Calculation_Statistical
PHPExcel_Calculation_Statistical

Code

public static function MEDIAN() {

  // Return value
  $returnValue = PHPExcel_Calculation_Functions::NaN();
  $mArgs = array();

  // Loop through arguments
  $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
  foreach ($aArgs as $arg) {

    // Is it a numeric value?
    if (is_numeric($arg) && !is_string($arg)) {
      $mArgs[] = $arg;
    }
  }
  $mValueCount = count($mArgs);
  if ($mValueCount > 0) {
    sort($mArgs, SORT_NUMERIC);
    $mValueCount = $mValueCount / 2;
    if ($mValueCount == floor($mValueCount)) {
      $returnValue = ($mArgs[$mValueCount--] + $mArgs[$mValueCount]) / 2;
    }
    else {
      $mValueCount == floor($mValueCount);
      $returnValue = $mArgs[$mValueCount];
    }
  }

  // Return
  return $returnValue;
}