If I iterate over an array twice, once by reference and then by value, PHP will overwrite the last value in the array if I use the same variable name for each loop. This is best illustrated by an example:
$array = range(1,5);
foreach($array as &$element)
{
$element *= 2;
}
print_r($array);
foreach($array as $element) { }
print_r($array);
Output:
Array ([0] => 2 [1] => 4 [2] => 6 [3] => 8 [4] => 10 )
Array ([0] => 2 [1] => 4 [2] => 6 [3] => 8 [4] => 8 )
, , , . , , $element, , $element, , .