I'm coming to Php from Javascript and I can't understand why, to get, transform and return an array in Php, you have to use the "&" aka "reference" symbol in the foreach()...
$some_array = array(1, 2, 3);
function test($a) {
foreach ($a as $k => &$v) {
$v = 'Hello!';
};
return $a;
};
$result = test($some_array);
var_dump($result); // array('Hello!', 'Hello!', 'Hello!');
But with:
function test($a) {
foreach ($a as $k => $v) {
$v = 'Hello!';
};
return $a;
};
[...]
var_dump($result); // array(1, 2, 3)
foreach. see: eval.in/726978. i.e. it gives the same result without references. You need to know the element keys. Just a different way of getting the same effect.