I scale an array of readings in place with foreach ($values as &$v) { $v = $v * 2; }. Later in the same function a second loop, foreach ($values as $v) { echo $v; }, prints the last value wrong: for [1, 2, 3] I expect 2, 4, 6 and get 2, 4, 4. After that the array itself really contains 2, 4, 4.
The second loop only reads. How can it change the array, and how should I write the first loop?




