How to use array_walk_recursive function in PHP
This article is about how to use the array_walk_recursive function in PHP. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Array_walk_recursive applies the user function recursively to each member of the array.
This function is somewhat similar to array_map, except that you don't need to write recursion.
Function myfunction (& $value, $key, $p) {if ($value = = 'xxx') {$value = $p;}} $a = array ("a" = > "red", "b" = > "green", "c" = > "blue",' d' = > ['x' = > 'xxx', 'y' = >' yyy']); array_walk_recursive ($a, "myfunction", 'green'); print_r ($a)
Output:
Array
(
[a] = > red
[B] = > green
[C] = > blue
[d] = > Array
(
[X] = > green
[y] = > yyy
)
)
Thank you for reading! This is the end of the article on "how to use the array_walk_recursive function in PHP". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!