Array_walk_recursive user functions recursively in each member of an array
Basic syntax
BOOL Array_walk_recursive (array & $input, callable $funcname [, mixed $userdata = NULL])
Applies the user-defined function funcname to each cell in an array. This function recursively goes to a deeper array. In the FuncName function, the key name and key value of the array are the parameters of the function.
Parameter introduction:
| Parameters |
Description |
| Input |
Necessary. The array entered. |
| FuncName |
Necessary. The name of the user-defined function. Typically, the funcname accepts two parameters. The value of the input parameter is the first, and the key name is the second. |
| UserData |
Optional. If an optional parameter userdata is provided, it is passed as the third argument to callback funcname. |
Note: If funcname needs to act directly on the values in the array, the first argument to FuncName is specified as a reference. Any changes to these units will also change the original array itself.
return value
Returns TRUE on success or FALSE on failure.
Instance:
<?php
$sweet = Array (
' a ' => ' apple ', '
b ' => ' banana '
);
$fruits = Array (
' sweet ' => $sweet,
' sour ' => ' lemon '
);
function Test_print ($item, $key) {
echo $key holds $item <br/>;
}
Array_walk_recursive ($fruits, ' test_print ');
Run Result:
A holds Apple
B holds banana
Sour holds lemon
Thank you for reading, I hope to help you, thank you for your support for this site!