array_walk_recursive
Apply a user function recursively to every member of an array
Descriptionboolarray_walk_recursivearrayinputstringfuncnamemixeduserdata
&return.success;
Applies the user-defined function function to each
element of the array array. This function will recur
into deeper arrays. Typically, function takes on two
parameters. The array parameter's value being the first, and
the key/index second. If the optional userdata
parameter is supplied, it will be passed as the third parameter to
the callback function.
If function needs to be working with the
actual values of the array, specify the first parameter of
function as a
reference. Then,
any changes made to those elements will be made in the
original array itself.
array_walk_recursive example
'apple', 'b' => 'banana');
$fruits = array('sweet' => $sweet, 'sour' => 'lemon');
function test_alter(&$item1, $key, $prefix)
{
$item1 = "$prefix: $item1";
}
function test_print($item2, $key)
{
echo "$key. $item2 \n";
}
echo "Before ...:\n";
array_walk($fruits, 'test_print');
array_walk($fruits, 'test_alter', 'fruit');
echo "... and after:\n";
array_walk($fruits, 'test_print');
?>
]]>
The printout of the program above will be:
See also array_walk