I was looking for the use-cases of array_walk()
, so I went to the PHP documentation and view this example.
But I don't understand how the function test_alter()
modifies the value of the array.
Can you explain me?
Here's the code:
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
function test_alter(&$item1, $key, $prefix)
{
$item1 = "$prefix: $item1";
}
function test_print($item2, $key)
{
echo "$key. $item2<br />\n";
}
echo "Before ...:\n";
array_walk($fruits, 'test_print');
array_walk($fruits, 'test_alter', 'fruit');
print_r($fruits);