You are here

public static function PHPExcel_Calculation_Statistical::MAXIF 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::MAXIF()

* MAXIF * * Counts the maximum value within a range of cells that contain numbers within the list of arguments * * Excel Function: * MAXIF(value1[,value2[, ...]],condition) * * @access public * @category Mathematical and Trigonometric Functions *

Parameters

mixed $arg,... Data values: * @param string $condition The criteria that defines which cells will be checked. * @return float

File

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

Class

PHPExcel_Calculation_Statistical
PHPExcel_Calculation_Statistical

Code

public static function MAXIF($aArgs, $condition, $sumArgs = array()) {

  // Return value
  $returnValue = null;
  $aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs);
  $sumArgs = PHPExcel_Calculation_Functions::flattenArray($sumArgs);
  if (empty($sumArgs)) {
    $sumArgs = $aArgs;
  }
  $condition = PHPExcel_Calculation_Functions::_ifCondition($condition);

  // Loop through arguments
  foreach ($aArgs as $key => $arg) {
    if (!is_numeric($arg)) {
      $arg = PHPExcel_Calculation::_wrapResult(strtoupper($arg));
    }
    $testCondition = '=' . $arg . $condition;
    if (PHPExcel_Calculation::getInstance()
      ->_calculateFormulaValue($testCondition)) {
      if (is_null($returnValue) || $arg > $returnValue) {
        $returnValue = $arg;
      }
    }
  }

  // Return
  return $returnValue;
}