| 1 |
<?php |
| 2 |
|
| 3 |
namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\Statistical; |
| 4 |
|
| 5 |
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Functions; |
| 6 |
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ErrorValue; |
| 7 |
|
| 8 |
class Minimum extends MaxMinBase |
| 9 |
{ |
| 10 |
/** |
| 11 |
* MIN. |
| 12 |
* |
| 13 |
* MIN returns the value of the element of the values passed that has the smallest value, |
| 14 |
* with negative numbers considered smaller than positive numbers. |
| 15 |
* |
| 16 |
* Excel Function: |
| 17 |
* MIN(value1[,value2[, ...]]) |
| 18 |
* |
| 19 |
* @param mixed ...$args Data values |
| 20 |
* @return float|int|string |
| 21 |
*/ |
| 22 |
public static function min(...$args) |
| 23 |
{ |
| 24 |
$returnValue = null; |
| 25 |
|
| 26 |
// Loop through arguments |
| 27 |
$aArgs = Functions::flattenArray($args); |
| 28 |
foreach ($aArgs as $arg) { |
| 29 |
if (ErrorValue::isError($arg, true)) { |
| 30 |
$returnValue = $arg; |
| 31 |
|
| 32 |
break; |
| 33 |
} |
| 34 |
// Is it a numeric value? |
| 35 |
if ((is_numeric($arg)) && (!is_string($arg))) { |
| 36 |
if (($returnValue === null) || ($arg < $returnValue)) { |
| 37 |
$returnValue = $arg; |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
if ($returnValue === null) { |
| 43 |
return 0; |
| 44 |
} |
| 45 |
/** @var float|int|string $returnValue */ |
| 46 |
|
| 47 |
return $returnValue; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* MINA. |
| 52 |
* |
| 53 |
* Returns the smallest value in a list of arguments, including numbers, text, and logical values |
| 54 |
* |
| 55 |
* Excel Function: |
| 56 |
* MINA(value1[,value2[, ...]]) |
| 57 |
* |
| 58 |
* @param mixed ...$args Data values |
| 59 |
* @return float|int|string |
| 60 |
*/ |
| 61 |
public static function minA(...$args) |
| 62 |
{ |
| 63 |
$returnValue = null; |
| 64 |
|
| 65 |
// Loop through arguments |
| 66 |
$aArgs = Functions::flattenArray($args); |
| 67 |
foreach ($aArgs as $arg) { |
| 68 |
if (ErrorValue::isError($arg, true)) { |
| 69 |
$returnValue = $arg; |
| 70 |
|
| 71 |
break; |
| 72 |
} |
| 73 |
// Is it a numeric value? |
| 74 |
if ((is_numeric($arg)) || (is_bool($arg)) || ((is_string($arg) && ($arg != '')))) { |
| 75 |
$arg = self::datatypeAdjustmentAllowStrings($arg); |
| 76 |
if (($returnValue === null) || ($arg < $returnValue)) { |
| 77 |
$returnValue = $arg; |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
if ($returnValue === null) { |
| 83 |
return 0; |
| 84 |
} |
| 85 |
/** @var float|int|string $returnValue */ |
| 86 |
|
| 87 |
return $returnValue; |
| 88 |
} |
| 89 |
} |
| 90 |
|