reference/array/functions/array-walk.xml
cec5275f23d2db648df30a5702b378044431be97
...
...
@@ -8,10 +8,10 @@
8
8
<refsect1 role="description">
9
9
&reftitle.description;
10
10
<methodsynopsis>
11
-
<type>bool</type><methodname>array_walk</methodname>
11
+
<type>true</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>
...
...
@@ -86,19 +86,46 @@
86
86
<refsect1 role="returnvalues">
87
87
&reftitle.returnvalues;
88
88
<para>
89
-
Returns &true;.
89
+
&return.true.always;
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
+
&return.type.true;
117
+
<row>
118
+
<entry>8.0.0</entry>
119
+
<entry>
120
+
If <parameter>callback</parameter> expects the second or third parameter to be passed
121
+
by reference, this function will now emit an <constant>E_WARNING</constant>.
122
+
</entry>
123
+
</row>
124
+
</tbody>
125
+
</tgroup>
126
+
</informaltable>
127
+
</refsect1>
128
+

102
129
<refsect1 role="examples">
103
130
&reftitle.examples;
104
131
<para>
...
...
@@ -142,6 +169,31 @@ d. fruit: lemon
142
169
a. fruit: orange
143
170
b. fruit: banana
144
171
c. fruit: apple
172
+
]]>
173
+
</screen>
174
+
</example>
175
+
</para>
176
+
<para>
177
+
<example>
178
+
<title><function>array_walk</function> example using anonymous function</title>
179
+
<programlisting role="php">
180
+
<![CDATA[
181
+
<?php
182
+
$elements = ['a', 'b', 'c'];
183
+

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

188
+
?>
189
+
]]>
190
+
</programlisting>
191
+
&example.outputs;
192
+
<screen role="php">
193
+
<![CDATA[
194
+
0 => a
195
+
1 => b
196
+
2 => c
145
197
]]>
146
198
</screen>
147
199
</example>
148
200