php - change initial array inside the foreach loop? - Stack ... 2010年2月27日 - i want to have a foreach loop where the initial array is changed inside .... don't really understand why $value is referenced and not $array ...but ...
You can in fact use foreach to change array elements in PHP foreach ($array as &$value) {}. This is only valid in PHP5 and can have very bad consequences for example run this piece of code:
Changing array values in foreach loop PHP Server Side Scripting ... changing array values in foreach loop. ... instructs php to take the value of whatever is in the existing array, and then whilst the loop executes, ...