[doc-en] master: Add example on updating values with array_walk_recursive. (#3365)
| From: | gitomato via GitHub | Date: | Thu, 27 Aug 2026 08:41:24 +0000 |
| Subject: | [doc-en] master: Add example on updating values with array_walk_recursive. (#3365) | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-23652@lists.php.net to get a copy of this message | ||
Author: gitomato (gitomato)
Committer: GitHub (web-flow)
Pusher: lacatoire
Date: 2026-08-27T10:41:21+02:00
Commit: https://github.com/php/doc-en/commit/0d8ee2131b4da66a4d274c576da9137c2a7963d5
Raw diff: https://github.com/php/doc-en/commit/0d8ee2131b4da66a4d274c576da9137c2a7963d5.diff
Add example on updating values with array_walk_recursive. (#3365)
* Add example on updating values with array_walk_recursive.
* Address review: add intro text, fix title, clean up code
* fix: use simpara for inline-only content in array_walk_recursive example intro
---------
Co-authored-by: lacatoire <la.catoire@gmail.com>
Co-authored-by: lcatoire <lcatoire@carter-cash.com>
Changed paths:
M reference/array/functions/array-walk-recursive.xml
Diff:
diff --git a/reference/array/functions/array-walk-recursive.xml
b/reference/array/functions/array-walk-recursive.xml
index 209b4180e0e2..835d8c234410 100644
--- a/reference/array/functions/array-walk-recursive.xml
+++ b/reference/array/functions/array-walk-recursive.xml
@@ -133,6 +133,44 @@ sour holds lemon
</para>
</example>
</para>
+ <simpara>
+ <function>array_walk_recursive</function> can also be used to update values
+ in place by passing the callback parameter by reference.
+ </simpara>
+ <para>
+ <example>
+ <title>Updating values in place</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$sweet = ['a' => 'apple', 'b' => 'banana'];
+$fruits = ['sweet' => $sweet, 'sour' => 'lemon'];
+
+function test_update(&$item)
+{
+ $item = strtoupper($item);
+}
+
+function test_print($item, $key)
+{
+ echo "$key holds $item\n";
+}
+
+array_walk_recursive($fruits, 'test_update');
+array_walk_recursive($fruits, 'test_print');
+?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+a holds APPLE
+b holds BANANA
+sour holds LEMON
+]]>
+ </screen>
+ </example>
+ </para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;