3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 7.0.20, 7.1.5 - 7.1.10, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
12array(2) { [1]=> string(5) "apple" [2]=> string(6) "banana" }

preferences:
121.21 ms | 403 KiB | 146 Q