3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = ['one', 'two', 'three', 'foo', 'bar', 'etc']; $prev = ''; foreach ($arr as &$ref) { $ref = $prev . $ref; $prev = $ref; } var_export($arr); $arr = ['one', 'two', 'three', 'foo', 'bar', 'etc']; var_export( array_map( function($v) { static $prev = ''; $v = $prev . $v; $prev = $v; return $v; }, $arr ) );

preferences:
56.24 ms | 405 KiB | 5 Q