Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use array_walk_recursive function in PHP

Shulou Source: shulou.com Published: 2022-06-01 02:56:06 11月14日 Update

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!

Tags: Function content more article recursion good practical just member array article user see knowledge reference help application related output Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Linux Shulou Information MariaDB macOS