reference/array/functions/array-walk.xml
d45ff7a3e78243470d1b7e5141d7ded022286d7f
...
...
@@ -9,9 +9,9 @@
9
9
&reftitle.description;
10
10
<methodsynopsis>
11
11
<type>bool</type><methodname>array_walk</methodname>
12
-
<methodparam><type>array</type><parameter role="reference">array</parameter></methodparam>
12
+
<methodparam><type class="union"><type>array</type><type>object</type></type><parameter role="reference">array</parameter></methodparam>
13
13
<methodparam><type>callable</type><parameter>callback</parameter></methodparam>
14
-
<methodparam choice="opt"><type>mixed</type><parameter>userdata</parameter><initializer>&null;</initializer></methodparam>
14
+
<methodparam choice="opt"><type>mixed</type><parameter>arg</parameter><initializer>&null;</initializer></methodparam>
15
15
</methodsynopsis>
16
16
<simpara>
17
17
Applies the user-defined <parameter>callback</parameter> function to each
...
...
@@ -71,10 +71,10 @@
71
71
</listitem>
72
72
</varlistentry>
73
73
<varlistentry>
74
-
<term><parameter>userdata</parameter></term>
74
+
<term><parameter>arg</parameter></term>
75
75
<listitem>
76
76
<para>
77
-
If the optional <parameter>userdata</parameter> parameter is supplied,
77
+
If the optional <parameter>arg</parameter> parameter is supplied,
78
78
it will be passed as the third parameter to the
79
79
<parameter>callback</parameter>.
80
80
</para>
...
...
@@ -86,18 +86,45 @@
86
86
<refsect1 role="returnvalues">
87
87
&reftitle.returnvalues;
88
88
<para>
89
-
&return.success;
89
+
Returns &true;.
90
90
</para>
91
91
</refsect1>
92
+

92
93
<refsect1 role="errors">
93
94
&reftitle.errors;
94
95
<para>
95
-
If function <parameter>callback</parameter> requires more parameters than
96
-
given to it, an error of level <link linkend="errorfunc.constants">
97
-
E_WARNING</link> will be generated each time <function>array_walk</function>
98
-
calls <parameter>callback</parameter>.
96
+
As of PHP 7.1.0, an <classname>ArgumentCountError</classname> will be thrown if the <parameter>callback</parameter> function
97
+
requires more than 2 parameters (the value and key of the array member),
98
+
or more than 3 parameters if the <parameter>arg</parameter> is also passed.
99
+
Previously, in this case
100
+
an error of level <link linkend="errorfunc.constants">E_WARNING</link> would be generated each time
101
+
<function>array_walk</function> calls <parameter>callback</parameter>.
99
102
</para>
100
103
</refsect1>
104
+

105
+
<refsect1 role="changelog">
106
+
&reftitle.changelog;
107
+
<informaltable>
108
+
<tgroup cols="2">
109
+
<thead>
110
+
<row>
111
+
<entry>&Version;</entry>
112
+
<entry>&Description;</entry>
113
+
</row>
114
+
</thead>
115
+
<tbody>
116
+
<row>
117
+
<entry>8.0.0</entry>
118
+
<entry>
119
+
If <parameter>callback</parameter> expects the second or third parameter to be passed
120
+
by reference, this function will now emit an <constant>E_WARNING</constant>.
121
+
</entry>
122
+
</row>
123
+
</tbody>
124
+
</tgroup>
125
+
</informaltable>
126
+
</refsect1>
127
+

101
128
<refsect1 role="examples">
102
129
&reftitle.examples;
103
130
<para>
...
...
@@ -115,7 +142,7 @@ function test_alter(&$item1, $key, $prefix)
115
142

116
143
function test_print($item2, $key)
117
144
{
118
-
echo "$key. $item2<br />\n";
145
+
echo "$key. $item2\n";
119
146
}
120
147

121
148
echo "Before ...:\n";
...
...
@@ -145,6 +172,31 @@ c. fruit: apple
145
172
</screen>
146
173
</example>
147
174
</para>
175
+
<para>
176
+
<example>
177
+
<title><function>array_walk</function> example using anonymous function</title>
178
+
<programlisting role="php">
179
+
<![CDATA[
180
+
<?php
181
+
$elements = ['a', 'b', 'c'];
182
+

183
+
array_walk($elements, function ($value, $key) {
184
+
echo "{$key} => {$value}\n";
185
+
});
186
+

187
+
?>
188
+
]]>
189
+
</programlisting>
190
+
&example.outputs;
191
+
<screen role="php">
192
+
<![CDATA[
193
+
0 => a
194
+
1 => b
195
+
2 => c
196
+
]]>
197
+
</screen>
198
+
</example>
199
+
</para>
148
200
</refsect1>
149
201
<refsect1 role="seealso">
150
202
&reftitle.seealso;
...
...
@@ -156,7 +208,6 @@ c. fruit: apple
156
208
<member><function>each</function></member>
157
209
<member><function>call_user_func_array</function></member>
158
210
<member><function>array_map</function></member>
159
-
<member>&seealso.callback;</member>
160
211
<member>&foreach;</member>
161
212
</simplelist>
162
213
</para>
163
214