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) { $child[$i] = $fruit; unset($child[$key]); $i++; } var_dump($child);

preferences:
48.32 ms | 402 KiB | 5 Q