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