What are the differences between using array_walk, array_map, and foreach loops to update array values in PHP?

When you need to update values in an array in PHP, you can use array_walk, array_map, or foreach loops. The main difference between them is in how they handle the iteration and updating of array values. - array_walk allows you to modify the values of an array in place by passing each element by reference to a user-defined callback function. - array_map creates a new array by applying a callback function to each element of the original array. It does not modify the original array. - foreach loop is a traditional way of iterating over an array and updating values directly. Here is an example of how you can use array_walk to update array values in PHP:

// Original array
$numbers = [1, 2, 3, 4, 5];

// Update each value by squaring it
array_walk($numbers, function (&$value) {
    $value = $value * $value;
});

// Output the updated array
print_r($numbers);