array_walk() Function in PHP 8.2, PHP 8.3 & PHP 8.4 With Example

`array_walk()` Function in PHP 8.2, PHP 8.3 & PHP 8.4

The `array_walk()` function in PHP is used to apply a user-defined function to each element of an array. It operates on the original array and can modify its values. Syntax:
array_walk(array &$array, callable $callback, mixed $userdata = null): bool
Example 1: Basic Usage
<?php
function myFunction(&$value, $key) {
$value = strtoupper($value); // Convert value to uppercase
}
$array = ["apple", "banana", "cherry"];
array_walk($array, "myFunction");
print_r($array);
?>
Output:-
Array
(
[0] => APPLE
[1] => BANANA
[2] => CHERRY
)
Example 2: Using Additional Parameter (`$userdata`)
<?php
function addPrefix(&$value, $key, $prefix) {
$value = $prefix . $value;
}
$fruits = ["apple", "banana", "cherry"];
array_walk($fruits, "addPrefix", "Fruit: ");
print_r($fruits);
?>
Output:
Array
(
[0] => Fruit: apple
[1] => Fruit: banana
[2] => Fruit: cherry
)