English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_walk_recursive() Function Usage and Example

PHP Array Function Manual

The array_walk_recursive() function applies the user function recursively to each member of the array

Syntax

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

Definition and Usage

The array_walk_recursive() function runs the user-defined function for each array element. The keys and values are parameters in the function.

Apply the user-defined function funcname to each element of the array. This function will recurse into deeper arrays.

Return Value

 Returns TRUE on success, or FALSE on failure.

Parameter

Serial NumberParameters and Description
1

array(Required)

It specifies an array.

2

funcname(Required)

The name of the user-defined function.

3

paramter(Optional)

It specifies a parameter for the user-defined function.

Online Example

Apply the user-defined function call_back_function to each element of the array

<?php
   function call_back_function($value,$key) {
      echo "Key $key has the value $value \n";
   }
   
   $input1 = array("a"=>"green", "b"=>"brown", "c"=>"blue" );
   $input2 = array($input1, "d"=>"yellow", "e"=>"black");
   
   array_walk_recursive($input2,"call_back_function");
?>
Test and see‹/›

Output result:

The value of key 'a' is 'green' 
The value of key 'b' is 'brown' 
The value of key 'c' is 'blue' 
The value of key 'd' is 'yellow' 
The value of key 'e' is 'black'

   PHP Array Function Manual