FOREACH reference:

<?php 
$myArray = array('t','h','i','s','i','s','a','n','a','r','r','a','y');
foreach($myArray as &$value) {
  echo $value;
}
echo PHP_EOL;
foreach($myArray as $v) {
  echo $v;
}
echo PHP_EOL;
foreach($myArray as $value) {
  echo $value;
}
/*
OUTPUT:
thisisanarray
thisisanarray
thisisanarraa
*/

The reason is almost obvious when you know you’re using reference and you know how reference works. When you are using reference , $value is a pointer to your element , not a copied value. So when you loop over your array, $value will be each element from your array. Everything is ok until you use the variable again. Everything you will assign to it , will also change the value of the reference. Another example to explain :

<?php   
$myArray = array('t','h','i','s');  
 foreach($myArray as &$value) {
           echo $value;
   }   
  echo PHP_EOL;
  $value = 'reference value changed';
  var_dump($myArray);
/*  OUTPUT:  
this 
array(4) {
  [0]= 
  string(1) "t"
  [1]=---->
  string(1) "h"
  [2]=>
  string(1) "i"
  [3]=>
  &string(23) "reference value changed"
}
*/

You only need to unset the reference. In this case : $value. If you want a more detail explication , check out Johannes Schlüter blog