PHP - Function array_walk_recursive()


Advertisements


Syntax

array_walk_recursive( $array, $funcname [,$parameter])

Definition and Usage

The array_walk_recursive() function runs each array element in a user-made function. The array's keys and values are parameters in the function. The difference between this function and the array_walk() function is that with this function you can work with deeper arrays (an array inside an array). Returns True or False.

Parameters

Sr.No Parameter & Description
1

array

Required. Specifies an array.

2

funcname

Required. The name of the user-made function.

3

paramter

Optional. Specifies a parameter to the user-made function.

Example

Try out following example −

<?php
   function call_back_function($value,$key) {
      echo "The key $key has the value $value \n";
   }
   
   $array1 = array("a"=>"green", "b"=>"brown", "c"=>"blue" );
   $array2 = array($array1, "d"=>"yellow", "e"=>"black");
   
   array_walk_recursive($array2,"call_back_function");
?> 

This will produce the following result −

The key a has the value green
The key b has the value brown
The key c has the value blue
The key d has the value yellow
The key e has the value black

php_function_reference.htm