Apply a user-defined function to each element of an array.
| <?php function myfunction($value,$key) { echo “The key $key has the value $value<br>”; } $a1=array(“a”=>“red”,“b”=>“green”); $a2=array($a1,“1”=>“blue”,“2”=>“yellow”); array_walk_recursive($a2,“myfunction”); ?> |
The array_walk_recursive() function applies a user-defined function to each element of an array, including nested arrays. Unlike array_walk(), this function allows you to handle deeper, multidimensional arrays by passing both the keys and values as parameters to the function.
| array_walk_recursive(array, myfunction, parameter…) |
|
Parameter |
Description |
|
array |
Required. Providing an array. |
|
myfunction |
Required. The name of the user-defined function. |
|
parameter,… |
Optional. Specifies parameters for the user-defined function. You can pass one parameter or multiple parameters to the function. |
|
Return Value: |
Returns |
|
PHP Version: |
5+ |