I have a very little piece of code for testing an array_walk test.
I thought that I could do the same with foreach but then when I pass the value it doesn't get modified:
<?php
$frutas = [ "d" => "limón", "a" => "naranja", "b" => "banana", "c" => "manzana" ];
function test_alter(&$elemento)
{
$elemento = "prefijo: $elemento";
echo "$elemento <br>";
}
foreach($frutas as $clave => $valor) {
test_alter($valor, $clave);
}
print_r( $frutas );
?>
Which outputs:
prefijo: limón
prefijo: naranja
prefijo: banana
prefijo: manzana
Array ( [d] => limón [a] => naranja [b] => banana [c] => manzana )
Obviously not modifying array value although its passed by reference.