PHP array_walk_recursive() Function
In this chapter you will learn:
- Definition for PHP array_walk_recursive() Function
- Syntax for PHP array_walk_recursive() Function
- Parameter for PHP array_walk_recursive() Function
- Example - Run user defined function on array element
Definition
The array_walk_recursive() function runs a user-defined function on each array element including inner array.
Syntax
PHP array_walk_recursive() Function has the following syntax.
array_walk_recursive(array,myfunction,parameter...)
Parameter
Parameter | Is Required | Description |
---|---|---|
array | Required. | Array to walk on |
myfunction | Required. | The name of the user-defined function |
parameter,... | Optional. | Parameter to the user-defined function. You can assign one parameter to the function, or as many as you like. |
Example
Run user defined function on array element
<?php/*j a va 2 s . c o m*/
function myfunction($value,$key){
echo "The key $key has the value $value<br>";
}
$a1=array("a"=>"PHP","b"=>"java2s.com");
$a2=array($a1,"1"=>"One","2"=>"Two");
array_walk_recursive($a2,"myfunction");
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP arsort() Function
- Note for PHP arsort() Function
- Syntax for PHP arsort() Function
- Parameter for PHP arsort() Function
- Example - reverse sorts array by its values
- Example - reverse sorts array by its values and output its keys and values
- Example - arsort() example using case-insensitive natural ordering
Home » PHP Tutorial » PHP Array Functions