reference/array/functions/array-walk.xml
d45ff7a3e78243470d1b7e5141d7ded022286d7f
...
...
@@ -11,7 +11,7 @@
11
11
<type>bool</type><methodname>array_walk</methodname>
12
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>
...
...
@@ -89,16 +89,42 @@
89
89
Returns &true;.
90
90
</para>
91
91
</refsect1>
92
+

92
93
<refsect1 role="errors">
93
94
&reftitle.errors;
94
95
<para>
95
96
As of PHP 7.1.0, an <classname>ArgumentCountError</classname> will be thrown if the <parameter>callback</parameter> function
96
-
requires more than 2 parameters (the value and key of the array member).
97
-
Previously, if the <parameter>callback</parameter> function required more than 2 parameters,
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
98
100
an error of level <link linkend="errorfunc.constants">E_WARNING</link> would be generated each time
99
101
<function>array_walk</function> calls <parameter>callback</parameter>.
100
102
</para>
101
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
+

102
128
<refsect1 role="examples">
103
129
&reftitle.examples;
104
130
<para>
...
...
@@ -146,6 +172,31 @@ c. fruit: apple
146
172
</screen>
147
173
</example>
148
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>
149
200
</refsect1>
150
201
<refsect1 role="seealso">
151
202
&reftitle.seealso;
152
203