3v4l.org

run code in 500+ 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.90.0110.00716.75
8.5.80.0070.00216.93
8.5.70.0130.00416.58
8.5.60.0070.01016.75
8.5.50.0080.01016.49
8.5.30.0120.00619.47
8.5.20.0110.00618.09
8.5.10.0100.00818.75
8.5.00.0110.00816.71
8.4.240.0160.00919.47
8.4.230.0100.01019.58
8.4.220.0100.01219.49
8.4.210.0130.00819.41
8.4.180.0110.01119.39
8.4.170.0130.01020.54
8.4.160.0130.00922.04
8.4.150.0110.01219.72
8.4.90.0140.00717.91
8.3.320.0050.01018.54
8.3.310.0040.00618.55
8.3.300.0140.00620.69
8.3.290.0120.00918.59
8.3.280.0120.01018.56
8.3.180.0120.00816.61
8.3.50.0100.01116.61
8.2.320.0140.00718.02
8.2.310.0160.00517.95

preferences:
41.91 ms | 614 KiB | 5 Q