Using array_walk() to Apply a Function to Each Element in PHP


Apply a user-defined function to every member of an array.

Source Code

function printWithPrefix($value, $key) {
    echo "The value of $key is $valuen";
}
$fruits = ['apple' => 'red', 'banana' => 'yellow'];
array_walk($fruits, 'printWithPrefix');
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments