modify array in loop
php
Solution
From the PHP manual:
Note: Unless the array is referenced, foreach operates on a copy of the specified array and not the array itself. foreach has some side effects on the array pointer. Don't rely on the array pointer during or after the foreach without resetting it.
Problem
Here is the code: ``` $arraya = array('a','b','c'); foreach($arraya as $key=>$value) { if($value == 'b') { $arraya[] = 'd'; //print_r($arraya); //$arraya now becomes array('a','b','c','d') } echo $key.' is '.$value."\n"; } ``` and it will get: ``` 0 is a 1 is b 2 is c ``` And I wonder why `3 is d` doesn't show up??