<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.array.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.array-walk-recursive.php',
    1 => 'array_walk_recursive',
    2 => 'Apply a user function recursively to every member of an array',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Array Functions',
  ),
  'prev' => 
  array (
    0 => 'function.array-walk.php',
    1 => 'array_walk',
  ),
  'next' => 
  array (
    0 => 'function.arsort.php',
    1 => 'arsort',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/array/functions/array-walk-recursive.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.array-walk-recursive" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array_walk_recursive</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">array_walk_recursive</span> &mdash; <span class="dc-title">Apply a user function recursively to every member of an array</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.array-walk-recursive-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>array_walk_recursive</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.object.php" class="type object">object</a></span></span> <code class="parameter reference">&$array</code></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$arg</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="language.types.singleton.php" class="type true">true</a></span></div>

  <p class="para rdfs-comment">
   Applies the user-defined <code class="parameter">callback</code> function to each
   element of the <code class="parameter">array</code>. This function will recurse
   into deeper arrays.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.array-walk-recursive-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">array</code></dt>
     <dd>
      <p class="para">
       The input array.
      </p>
     </dd>
    
    
     <dt><code class="parameter">callback</code></dt>
     <dd>
      <p class="para">
       Typically, <code class="parameter">callback</code> takes on two parameters.
       The <code class="parameter">array</code> parameter&#039;s value being the first, and
       the key/index second.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        If <code class="parameter">callback</code> needs to be working with the
        actual values of the array, specify the first parameter of
        <code class="parameter">callback</code> as a
        <a href="language.references.php" class="link">reference</a>. Then,
        any changes made to those elements will be made in the
        original array itself.
       </p>
      </p></blockquote>
     </dd>
    
    
     <dt><code class="parameter">arg</code></dt>
     <dd>
      <p class="para">
       If the optional <code class="parameter">arg</code> parameter is supplied,
       it will be passed as the third parameter to the
       <code class="parameter">callback</code>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>



 <div class="refsect1 returnvalues" id="refsect1-function.array-walk-recursive-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Always returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.array-walk-recursive-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
 <td>8.2.0</td>
 <td>
  The return type is <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> now; previously, it was <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>.
 </td>
</tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.array-walk-recursive-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>array_walk_recursive()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$sweet </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'a' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'apple'</span><span style="color: #007700">, </span><span style="color: #DD0000">'b' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'banana'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$fruits </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'sweet' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$sweet</span><span style="color: #007700">, </span><span style="color: #DD0000">'sour' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'lemon'</span><span style="color: #007700">);<br /><br />function </span><span style="color: #0000BB">test_print</span><span style="color: #007700">(</span><span style="color: #0000BB">$item</span><span style="color: #007700">, </span><span style="color: #0000BB">$key</span><span style="color: #007700">)<br />{<br />    echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$key</span><span style="color: #DD0000"> holds </span><span style="color: #0000BB">$item</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">array_walk_recursive</span><span style="color: #007700">(</span><span style="color: #0000BB">$fruits</span><span style="color: #007700">, </span><span style="color: #DD0000">'test_print'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">a holds apple
b holds banana
sour holds lemon</pre>
</div>
    </div>
    <div class="example-contents"><p>
     You may notice that the key &#039;<code class="literal">sweet</code>&#039; is never displayed. Any key that holds an
     <span class="type"><a href="language.types.array.php" class="type array">array</a></span> will not be passed to the function.
    </p></div>
   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.array-walk-recursive-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.array-walk.php" class="function" rel="rdfs-seeAlso">array_walk()</a> - Apply a user supplied function to every member of an array</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>