3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php set_time_limit(1); $arr = ['a' => 'apple', 'b' => 'banana']; $child = &$arr; $i = 1; foreach ($child AS $key => $fruit) { echo $i; $child[$i] = $fruit; unset($child[$key]); $i++; } var_dump($child);
based on 4DYmO
Output for 7.0.20 - 7.2.0
12array(2) { [1]=> string(5) "apple" [2]=> string(6) "banana" }