PHP array_walk() Function

PHP array_walk Function


Definition

The array_walk() function apply a user-defined function to every element of an array.

Syntax:

     array_walk(array, myfunction, parameter...)

Parameters:
Parameter Description
array Required. Specifying an array
myfunction Required. The name of the user-defined function
parameter,... Optional. Specifies a parameter to the user-defined function. You can assign one parameter to the function, or as many as you like

Example1 : we can see below example run each array element in a user-defined function: 

Output :

The key a has the value web
The key b has the value designing
The key c has the value house

Example2 : we can see below example also pass an indexed array as parameter to this function,

Output :

The value at index 0 is web

The value at index 1 is designing

The value at index 2 is house

The value at index 3 is online

 

Example3 : we can also change array element's value

Output :

Array
(
    [a] => online
    [b] => online
    [c] => online
)