reference/math/functions/min.xml
9d044185431afc63026546899216053820ac5d64
...
...
@@ -1,6 +1,6 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.min">
3
+
<refentry xml:id="function.min" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
5
<refname>min</refname>
6
6
<refpurpose>Find lowest value</refpurpose>
...
...
@@ -9,13 +9,13 @@
9
9
&reftitle.description;
10
10
<methodsynopsis>
11
11
<type>mixed</type><methodname>min</methodname>
12
-
<methodparam><type>array</type><parameter>values</parameter></methodparam>
12
+
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
13
+
<methodparam rep="repeat"><type>mixed</type><parameter>values</parameter></methodparam>
13
14
</methodsynopsis>
15
+
<simpara>Alternative signature (not supported with named arguments):</simpara>
14
16
<methodsynopsis>
15
17
<type>mixed</type><methodname>min</methodname>
16
-
<methodparam><type>mixed</type><parameter>value1</parameter></methodparam>
17
-
<methodparam><type>mixed</type><parameter>value2</parameter></methodparam>
18
-
<methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
18
+
<methodparam><type>array</type><parameter>value_array</parameter></methodparam>
19
19
</methodsynopsis>
20
20
<para>
21
21
If the first and only parameter is an array, <function>min</function>
...
...
@@ -26,14 +26,14 @@
26
26
<para>
27
27
Values of different types will be compared using the <link linkend="language.operators.comparison">
28
28
standard comparison rules</link>. For instance, a non-numeric <type>string</type> will be
29
-
compared to an <type>integer</type> as though it were <literal>0</literal>, but multiple non-numeric
29
+
compared to an <type>int</type> as though it were <literal>0</literal>, but multiple non-numeric
30
30
<type>string</type> values will be compared alphanumerically. The actual value returned will be of the
31
31
original type with no conversion applied.
32
32
</para>
33
33
</note>
34
34
<caution>
35
35
<simpara>
36
-
Be careful when passing arguments with mixed types values because
36
+
Be careful when passing arguments of different types because
37
37
<function>min</function> can produce unpredictable results.
38
38
</simpara>
39
39
</caution>
...
...
@@ -43,15 +43,7 @@
43
43
<para>
44
44
<variablelist>
45
45
<varlistentry>
46
-
<term><parameter>values</parameter></term>
47
-
<listitem>
48
-
<para>
49
-
An array containing the values.
50
-
</para>
51
-
</listitem>
52
-
</varlistentry>
53
-
<varlistentry>
54
-
<term><parameter>value1</parameter></term>
46
+
<term><parameter>value</parameter></term>
55
47
<listitem>
56
48
<para>
57
49
Any <link linkend="language.operators.comparison">comparable</link>
...
...
@@ -60,20 +52,19 @@
60
52
</listitem>
61
53
</varlistentry>
62
54
<varlistentry>
63
-
<term><parameter>value2</parameter></term>
55
+
<term><parameter>values</parameter></term>
64
56
<listitem>
65
57
<para>
66
58
Any <link linkend="language.operators.comparison">comparable</link>
67
-
value.
59
+
values.
68
60
</para>
69
61
</listitem>
70
62
</varlistentry>
71
63
<varlistentry>
72
-
<term><parameter>...</parameter></term>
64
+
<term><parameter>value_array</parameter></term>
73
65
<listitem>
74
66
<para>
75
-
Any <link linkend="language.operators.comparison">comparable</link>
76
-
value.
67
+
An array containing the values.
77
68
</para>
78
69
</listitem>
79
70
</varlistentry>
...
...
@@ -87,12 +78,47 @@
87
78
comparisons. If multiple values of different types evaluate as equal (e.g. <literal>0</literal>
88
79
and <literal>'abc'</literal>) the first provided to the function will be returned.
89
80
</para>
81
+
</refsect1>
90
82

83
+
<refsect1 role="errors">
84
+
&reftitle.errors;
91
85
<para>
92
-
If an empty array is passed, then &false; will be returned and an
93
-
<constant>E_WARNING</constant> error will be emitted.
86
+
If an empty array is passed, <function>min</function> throws a <classname>ValueError</classname>.
94
87
</para>
95
88
</refsect1>
89
+

90
+
<refsect1 role="changelog">
91
+
&reftitle.changelog;
92
+
<informaltable>
93
+
<tgroup cols="2">
94
+
<thead>
95
+
<row>
96
+
<entry>&Version;</entry>
97
+
<entry>&Description;</entry>
98
+
</row>
99
+
</thead>
100
+
<tbody>
101
+
<row>
102
+
<entry>8.0.0</entry>
103
+
<entry>
104
+
<function>min</function> throws a <classname>ValueError</classname> on failure now;
105
+
previously, &false; was returned and an <constant>E_WARNING</constant> error was emitted.
106
+
</entry>
107
+
</row>
108
+
<row>
109
+
<entry>8.0.0</entry>
110
+
<entry>
111
+
As <link linkend="migration80.incompatible.core.string-number-comparision">
112
+
string to number comparisons</link> were changed,
113
+
<function>min</function> no longer returns a
114
+
different value based on the argument order in those cases.
115
+
</entry>
116
+
</row>
117
+
</tbody>
118
+
</tgroup>
119
+
</informaltable>
120
+
</refsect1>
121
+

96
122
<refsect1 role="examples">
97
123
&reftitle.examples;
98
124
<para>
...
...
@@ -104,11 +130,6 @@
104
130
echo min(2, 3, 1, 6, 7); // 1
105
131
echo min(array(2, 4, 5)); // 2
106
132

107
-
// The string 'hello' when compared to an int is treated as 0
108
-
// Since the two values are equal, the order they are provided determines the result
109
-
echo min(0, 'hello'); // 0
110
-
echo min('hello', 0); // hello
111
-

112
133
// Here we are comparing -1 < 0, so -1 is the lowest value
113
134
echo min('hello', -1); // -1
114
135

...
...
@@ -124,7 +145,8 @@ $val = min(array(2, 4, 8), array(2, 5, 1)); // array(2, 4, 8)
124
145
$val = min('string', array(2, 5, 7), 42); // string
125
146

126
147
// If one argument is NULL or a boolean, it will be compared against
127
-
// other values using the rule FALSE < TRUE regardless of the other types involved
148
+
// other values using the rules FALSE < TRUE and NULL == FALSE regardless of the
149
+
// other types involved
128
150
// In the below examples, both -10 and 10 are treated as TRUE in the comparison
129
151
$val = min(-10, FALSE, 10); // FALSE
130
152
$val = min(-10, NULL, 10); // NULL
...
...
@@ -148,7 +170,6 @@ $val = min(0, TRUE); // 0
148
170
</para>
149
171
</refsect1>
150
172
</refentry>
151
-

152
173
<!-- Keep this comment at the end of the file
153
174
Local variables:
154
175
mode: sgml
155
176