3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = ['x', 'y', 'z']; $new = []; foreach($array as $element) { if ($element=='x') { $array[2] = 'a'; } $new[] = $element; } print_r($new);

preferences:
26.62 ms | 404 KiB | 5 Q