PHP array_walk_recursive()Functions
Examples
Apply a user-defined function to each element in the 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");
?>
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");
?>
Run example »
Definition and Usage
The array_walk_recursive() function applies a user-defined function to each element in the array. In the function, the array's key name and key value are parameters. This function differs from thearray_walk()function in that it can operate on deeper arrays (an array containing another array).
Syntax
array_walk_recursive(array,myfunction,parameter...)
| Parameters | Description |
|---|---|
| array | Required. Specifies the array. |
| myfunction | Required. The name of the user-defined function. |
| parameter,... | Optional. Specifies the parameters of the user-defined function. You can set one or more parameters for the function. |
Technical Details
| Return value: | Returns TRUE on success, otherwise returns FALSE. |
|---|---|
| PHP Version: | 5+ |
Complete PHP Array Reference Other Extensions