PHP array_walk_recursive() function

PHP array_walk() function
PHP arsort() function

The array_walk_recursive function iterates through elements of the array and passes each element’s key and value to a user-defined function. The keys and values of the array are the parameters of the user-defined function.

The difference between this function and the array_walk function is that it can work with the array inside an array.

We can change the value in the user-defined function by passing the first parameter ($value) as reference (&$value).

What is the syntax of the array_walk function in PHP?

array_walk_recursive(array, myfunction, parameter...)
arrayThe array to walking through – Required
my_functionThe user-defined function for array keys and values – Required
parameter,…Defines the parameters for the user-defined function – Optional
array_walk_recursive function in PHP

Examples of array_walk_recursive function

Example 1. Example of array_walk_recursive function.

function my_function($value,$key)
echo "$key $value";
$arra_2=array($array_1, "a"=>"B","b"=>"Y");
PHP array_walk() function
PHP arsort() function

1 comment

Tutor Network

Share this

Learn PHP from A to Z