<?php $array = ['x', 'y', 'z']; $new = []; foreach($array as $element) { if ($element=='x') { $array[2] = 'a'; } $new[] = $element; } print_r($new);
You have javascript disabled. You will not be able to edit any code.