3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'a', 'b', 'c', ]; function insertWhileIteratingForward($arr) { foreach ($arr as $index => $value) { if ($value === 'a' || $value === 'c') { array_splice($arr, $index, 0, ['new', 'new', 'new', 'new', 'new']); } } return $arr; } function insertWhileIteratingBackward($arr) { for ($index = count($arr) - 1; $index >= 0; --$index) { $value = $arr[$index]; if ($value === 'a' || $value === 'c') { array_splice($arr, $index, 0, ['new', 'new', 'new', 'new', 'new']); } } return $arr; } var_dump(insertWhileIteratingForward($array)); var_dump(insertWhileIteratingBackward($array));

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.10.0100.00818.75
8.5.00.0110.00816.71
8.4.160.0130.00922.04
8.4.150.0110.01219.72
8.4.90.0140.00717.91
8.3.290.0120.00918.59
8.3.280.0120.01018.56
8.3.180.0120.00816.61
8.3.50.0100.01116.61

preferences:
29.56 ms | 403 KiB | 5 Q