PHP array_walk_recursive() Function

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

ParameterIs RequiredDescription
arrayRequired.Array to walk on
myfunctionRequired.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//  w w w  .j  a v  a2  s  . c om
    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.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions