@@ 2340-2364 (lines=25) @@ | ||
2337 | * |
|
2338 | * @return float |
|
2339 | */ |
|
2340 | public static function MAXIF($aArgs, $condition, $sumArgs = []) |
|
2341 | { |
|
2342 | $returnValue = null; |
|
2343 | ||
2344 | $aArgs = Functions::flattenArray($aArgs); |
|
2345 | $sumArgs = Functions::flattenArray($sumArgs); |
|
2346 | if (empty($sumArgs)) { |
|
2347 | $sumArgs = $aArgs; |
|
2348 | } |
|
2349 | $condition = Functions::ifCondition($condition); |
|
2350 | // Loop through arguments |
|
2351 | foreach ($aArgs as $key => $arg) { |
|
2352 | if (!is_numeric($arg)) { |
|
2353 | $arg = \PhpOffice\PhpSpreadsheet\Calculation::wrapResult(strtoupper($arg)); |
|
2354 | } |
|
2355 | $testCondition = '=' . $arg . $condition; |
|
2356 | if (\PhpOffice\PhpSpreadsheet\Calculation::getInstance()->_calculateFormulaValue($testCondition)) { |
|
2357 | if ((is_null($returnValue)) || ($arg > $returnValue)) { |
|
2358 | $returnValue = $arg; |
|
2359 | } |
|
2360 | } |
|
2361 | } |
|
2362 | ||
2363 | return $returnValue; |
|
2364 | } |
|
2365 | ||
2366 | /** |
|
2367 | * MEDIAN. |
|
@@ 2504-2528 (lines=25) @@ | ||
2501 | * |
|
2502 | * @return float |
|
2503 | */ |
|
2504 | public static function MINIF($aArgs, $condition, $sumArgs = []) |
|
2505 | { |
|
2506 | $returnValue = null; |
|
2507 | ||
2508 | $aArgs = Functions::flattenArray($aArgs); |
|
2509 | $sumArgs = Functions::flattenArray($sumArgs); |
|
2510 | if (empty($sumArgs)) { |
|
2511 | $sumArgs = $aArgs; |
|
2512 | } |
|
2513 | $condition = Functions::ifCondition($condition); |
|
2514 | // Loop through arguments |
|
2515 | foreach ($aArgs as $key => $arg) { |
|
2516 | if (!is_numeric($arg)) { |
|
2517 | $arg = \PhpOffice\PhpSpreadsheet\Calculation::wrapResult(strtoupper($arg)); |
|
2518 | } |
|
2519 | $testCondition = '=' . $arg . $condition; |
|
2520 | if (\PhpOffice\PhpSpreadsheet\Calculation::getInstance()->_calculateFormulaValue($testCondition)) { |
|
2521 | if ((is_null($returnValue)) || ($arg < $returnValue)) { |
|
2522 | $returnValue = $arg; |
|
2523 | } |
|
2524 | } |
|
2525 | } |
|
2526 | ||
2527 | return $returnValue; |
|
2528 | } |
|
2529 | ||
2530 | // |
|
2531 | // Special variant of array_count_values that isn't limited to strings and integers, |