3v4l.org

run code in 300+ PHP versions simultaneously
<?php $values = array( 'foo' => 10, 'bar' => 20, 'baz' => 30 ); $newarray = array(); foreach($values as $k => $v) { $newarray[$k] = $v; if($k == 'bar') $newarray['qux'] = 21; } echo implode(' ', $newarray);

preferences:
26.43 ms | 404 KiB | 5 Q