PHP array_walk() Function

PHP array_walk() Function

The array_walk() function in PHP is used to apply the user-defined callback function to each element of the array. This function returns a Boolean TRUE on success or FALSE on failure.

Syntax

Parameter

array(required)– This array represents the input array.

callable(required)- It takes two parameters. The first one is the array parameter’s value, and the second one is the key/index.

userdata(optional)- This parameter represents an extra parameter, and it will be passed as the third parameter to the callback. The default value is null.

Return

This function returns a Boolean value TRUE on success or FALSE on failure.

Error/Exception

This function throwsan ArgumentCountError if the callback function requires more than 2 parameters

Example 1

Output

Example 2

Output

Example 3

Output

Example 4

Output