Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

array_walk_recursive()

Example

Apply a user-defined function to each element of an array.

<?php
function myfunction($value,$key)
{
echo “The key $key has the value $value<br>”;
}
$a1=array(“a”=>“red”,“b”=>“green”);
$a2=array($a1,“1”=>“blue”,“2”=>“yellow”);
array_walk_recursive($a2,“myfunction”);
?>

Definition and Usage

The array_walk_recursive() function applies a user-defined function to each element of an array, including nested arrays. Unlike array_walk(), this function allows you to handle deeper, multidimensional arrays by passing both the keys and values as parameters to the function.

Syntax

array_walk_recursive(array, myfunction, parameter…)

Parameter Values

Parameter

Description

array

Required. Providing an array.

myfunction

Required. The name of the user-defined function.

parameter,…

Optional. Specifies parameters for the user-defined function. You can pass one parameter or multiple parameters to the function.

Technical Details

Return Value:

Returns TRUE on success or FALSE on failure.

PHP Version:

5+