Current Location: Home> Function Categories> array_walk_recursive

array_walk_recursive

Recursively apply user functions to each member in the array
Name:array_walk_recursive
Category:Array
Programming Language:php
One-line Description:Recursively apply user functions to each member in the array.

Example

Apply user-defined functions to each element in the array:

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">function</span> <span class="token function-definition function">myfunction</span> <span class="token punctuation">(</span> <span class="token variable">$value</span> <span class="token punctuation">,</span> <span class="token variable">$key</span> <span class="token punctuation">)</span>
<span class="token punctuation">{</span>
<span class="token keyword">echo</span> <span class="token string double-quoted-string">"The value of the key <span class="token interpolation"><span class="token variable">$key</span></span> is <span class="token interpolation"><span class="token variable">$value</span></span> .<br>"</span> <span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token variable">$a1</span> <span class="token operator">=</span> <span class="token keyword">array</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"a"</span> <span class="token operator">=></span> <span class="token string double-quoted-string">"red"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"b"</span> <span class="token operator">=></span> <span class="token string double-quoted-string">"green"</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token variable">$a2</span> <span class="token operator">=</span> <span class="token keyword">array</span> <span class="token punctuation">(</span> <span class="token variable">$a1</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"1"</span> <span class="token operator">=></span> <span class="token string double-quoted-string">"blue"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"2"</span> <span class="token operator">=></span> <span class="token string double-quoted-string">"yellow"</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token function"></span></span><mark><span class="token function">array_walk_recursive</span> <span class="token punctuation">(</span> <span class="token variable">$a2</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"myfunction"</span> <span class="token punctuation">)</span></mark><span class="token punctuation"></span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span>

Try it yourself

Related
Similar Functions
  • Assign values from an array to a set of variables list

    list

    Assignvaluesfromanar
  • Sort the array and maintain index relationships asort

    asort

    Sortthearrayandmaint
  • Randomly fetch one or more units from an array array_rand

    array_rand

    Randomlyfetchoneormo
  • Use the user-provided callback function to perform index checking to calculate the difference set of the array array_diff_uassoc

    array_diff_uassoc

    Usetheuser-providedc
  • Use user-defined comparison functions to sort key names in an array uksort

    uksort

    Useuser-definedcompa
  • Point the inner pointer of the array to the first unit reset

    reset

    Pointtheinnerpointer
  • Returns the current key/value pair in the array and moves the array pointer one step forward - This function has been abandoned since PHP 7.2.0. It is strongly recommended not to use this function. each

    each

    Returnsthecurrentkey
  • count alias sizeof

    sizeof

    countalias
Popular Articles