Apply a user-defined function to each element in the array:
<?phpfunction 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 in an array. In the function, the key name and key value of the array are parameters. This function differs from the array_walk() function in that it can operate on deeper arrays (an array within another array).
array_walk_recursive( array,myfunction,parameter... )
parameter | describe |
---|---|
array | Required. Specifies an array. |
myfunction | Required. The name of the user-defined function. |
parameter,... | Optional. Specifies the parameters of a user-defined function. You can set one or more parameters for the function. |
Return value: | Returns TRUE if successful, otherwise returns FALSE. |
---|---|
PHP version: | 5+ |