3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = '1_2_3_4_5'; // Get an array with 1, 2, 3, 4 and 5 $parts = explode('_', $input); $output = []; $i = 1; foreach ($parts as $part) { // array_slice() will take 1 to n elements from the array of numbers $values = array_slice($parts, 0, $i++); // Join the values $output[] = implode('_', $values); } print_r($output);

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.3.60.0160.00618.30
8.3.50.0030.01018.20
8.3.40.0100.01320.93
8.3.30.0120.00318.52
8.3.20.0040.00424.18
8.3.10.0070.00024.66
8.3.00.0040.00426.16
8.2.180.0100.01025.92
8.2.170.0080.00819.13
8.2.160.0060.00922.96
8.2.150.0040.00425.66
8.2.140.0040.00424.66
8.2.130.0050.00326.16
8.2.120.0080.00019.89
8.2.110.0030.00619.45
8.2.100.0090.00317.91
8.2.90.0030.00619.22
8.2.80.0050.00317.97
8.2.70.0040.00417.75
8.2.60.0050.01017.78
8.2.50.0040.00418.07
8.2.40.0060.00319.95
8.2.30.0030.00618.05
8.2.20.0040.00418.06
8.2.10.0000.00719.29
8.2.00.0040.00419.25
8.1.280.0100.00725.92
8.1.270.0030.00624.01
8.1.260.0090.00026.35
8.1.250.0040.00428.09
8.1.240.0050.00522.67
8.1.230.0070.00418.98
8.1.220.0040.00417.88
8.1.210.0000.00818.77
8.1.200.0030.00717.35
8.1.190.0050.00317.36
8.1.180.0080.00018.10
8.1.170.0040.00418.68
8.1.160.0040.00418.94
8.1.150.0000.00918.55
8.1.140.0000.00717.45
8.1.130.0000.00817.33
8.1.120.0000.00717.54
8.1.110.0050.00317.35
8.1.100.0000.00717.49
8.1.90.0040.00417.51
8.1.80.0000.00917.48
8.1.70.0040.00417.52
8.1.60.0030.00517.62
8.1.50.0060.00317.39
8.1.40.0040.00417.48
8.1.30.0040.00417.68
8.1.20.0000.00817.61
8.1.10.0000.00817.40
8.1.00.0040.00717.28
8.0.300.0040.00418.77
8.0.290.0040.00416.63
8.0.280.0040.00418.45
8.0.270.0000.00716.76
8.0.260.0080.00016.74
8.0.250.0030.00316.97
8.0.240.0030.00516.87
8.0.230.0080.00016.99
8.0.220.0030.00516.88
8.0.210.0070.00016.76
8.0.200.0030.00516.98
8.0.190.0000.00716.83
8.0.180.0020.00516.94
8.0.170.0000.00816.90
8.0.160.0040.00416.79
8.0.150.0070.00016.79
8.0.140.0040.00416.80
8.0.130.0000.00613.29
8.0.120.0000.00816.86
8.0.110.0000.00816.89
8.0.100.0000.00816.68
8.0.90.0090.00016.81
8.0.80.0030.00616.88
8.0.70.0060.00316.96
8.0.60.0070.00316.77
8.0.50.0040.00416.96
8.0.30.0050.00316.73
8.0.20.0040.00416.96
8.0.10.0040.00417.07
8.0.00.0040.00417.09
7.4.330.0000.00515.55
7.4.320.0000.00616.61
7.4.300.0030.00316.52
7.4.290.0080.00016.58
7.4.280.0040.00416.55
7.4.270.0000.00816.56
7.4.260.0050.00013.34
7.4.250.0000.00816.42
7.4.240.0040.00416.44
7.4.230.0070.00016.41
7.4.220.0020.00516.59
7.4.210.0040.00416.69
7.4.200.0000.00716.43
7.4.190.0040.00416.32
7.4.180.0040.00416.60
7.4.160.0040.00416.57
7.4.150.0040.00416.63
7.4.140.0020.00516.55
7.4.130.0040.00416.38
7.4.120.0040.00416.49
7.4.110.0040.00416.30
7.4.100.0040.00416.63
7.4.90.0040.00416.17
7.4.80.0000.00716.21
7.4.70.0040.00416.48
7.4.60.0000.00716.36
7.4.50.0000.00716.47
7.4.40.0000.00716.21
7.4.30.0040.00416.56
7.4.20.0000.00716.30
7.4.10.0000.00716.53
7.4.00.0030.00316.62
7.3.330.0040.00416.24
7.3.320.0030.00313.09
7.3.310.0000.00716.20
7.3.300.0070.00016.11
7.3.290.0000.00616.30
7.3.280.0060.00016.16
7.3.270.0030.00316.16
7.3.260.0030.00316.25
7.3.250.0030.00316.18
7.3.240.0000.00816.11
7.3.230.0040.00416.04
7.3.220.0000.00716.20
7.3.210.0030.00516.14
7.3.200.0070.00016.18
7.3.190.0000.00716.06
7.3.180.0030.00316.16
7.3.170.0030.00316.19
7.3.160.0060.00016.00
7.3.150.0000.00616.21
7.3.140.0040.00416.23
7.3.130.0000.00716.18
7.3.120.0000.00716.03
7.3.110.0030.00316.13
7.3.100.0000.00616.17
7.3.90.0070.00016.45
7.3.80.0030.00316.06
7.3.70.0000.00616.29
7.3.60.0000.00616.23
7.3.50.0040.00416.39
7.3.40.0040.00416.39
7.3.30.0040.00416.40
7.3.20.0040.00418.15
7.3.10.0000.00818.11
7.3.00.0030.00618.02

preferences:
62.84 ms | 400 KiB | 5 Q