Monday 26 August 2013

PHP Function array_walk_recursive()

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.

Paramters

ParameterDescription
arrayRequired. Specifies an array.
funcnameRequired. The name of the user-made function.
paramterOptional. 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<br />";
}

$array1 = array("a"=>"green", "b"=>"brown", "c"=>"blue" );
$array2 = array($array1, "d"=>"yellow", "e"=>"black");

array_walk_recursive($array,"call_back_function");
?> 
This will produce 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

No comments:

Post a Comment