3v4l.org

run code in 500+ PHP versions simultaneously
<?php $test = [ 'a', 'b', 'a', 'b', 'a', 'a', 'a' ]; $result = []; // The first two need to be setup manually. There should probably be a guard around this // with a length check for $test. $result[] = array_shift($test); $result[] = array_shift($test); // Inside the loop we'll keep removing items while(count($test)){ // Setup common variables $current = array_shift($test); $last = end($result); $last_char = $last[-1]; if(strlen($last) >= 2){ // If we have two (or more) characters at the end of the array, just append $result[] = $current; }elseif($current === $last_char){ // Also, if we have the same character as last time, just append $result[] = $current; }else{ // Otherwise we have a different character, so append the current to the previus $result[ count($result) - 1 ] = $last_char . $current; } } var_dump($result);

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.70.0110.01116.77
8.5.60.0070.01016.70
8.5.50.0110.00616.92
8.5.30.0070.01119.10
8.5.20.0120.00719.36
8.5.10.0090.00916.84
8.5.00.0100.01220.02
8.4.210.0150.00719.53
8.4.180.0160.00619.60
8.4.170.0150.01022.13
8.4.160.0090.01122.10
8.4.150.0070.00616.76
8.4.140.0110.01017.84
8.4.130.0120.00818.77
8.4.120.0100.00422.08
8.4.110.0090.00919.52
8.4.100.0170.00617.60
8.4.90.0100.00720.63
8.4.80.0100.00718.60
8.4.70.0100.01020.66
8.4.60.0080.00220.58
8.4.50.0070.00219.04
8.4.40.0040.00417.89
8.4.30.0130.00620.26
8.4.20.0140.00319.80
8.4.10.0060.00318.74
8.3.300.0140.00619.37
8.3.290.0110.01020.77
8.3.280.0120.00918.61
8.3.270.0090.01116.62
8.3.260.0150.00616.65
8.3.250.0080.01116.47
8.3.240.0150.00416.67
8.3.230.0080.00716.75
8.3.220.0110.00719.11
8.3.210.0080.00716.43
8.3.200.0060.00316.48
8.3.190.0070.00717.25
8.3.180.0090.00718.92
8.3.170.0050.00216.99
8.3.160.0040.01117.17
8.3.150.0150.00416.41
8.3.140.0120.00616.83
8.3.130.0050.00316.62
8.3.120.0080.00018.96
8.3.110.0100.01016.91
8.3.100.0060.00316.49
8.3.90.0040.00426.77
8.3.80.0030.00616.63
8.3.70.0130.00318.56
8.3.60.0110.00718.68
8.3.50.0040.01117.99
8.3.40.0100.00320.49
8.3.30.0110.00418.79
8.3.20.0000.00724.18
8.3.10.0050.00324.66
8.3.00.0000.00826.16
8.2.300.0150.00420.45
8.2.290.0120.00716.36
8.2.280.0070.00718.46
8.2.270.0040.01116.56
8.2.260.0050.00317.11
8.2.250.0060.00316.66
8.2.240.0030.00616.86
8.2.230.0000.00920.94
8.2.220.0000.00824.06
8.2.210.0060.01026.77
8.2.200.0090.00016.50
8.2.190.0120.00616.63
8.2.180.0100.01025.92
8.2.170.0040.01118.99
8.2.160.0130.00022.96
8.2.150.0050.00325.66
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0040.00426.16
8.2.110.0050.00520.94
8.2.100.0040.00717.84
8.2.90.0000.00819.20
8.2.80.0030.00617.97
8.2.70.0060.00317.75
8.2.60.0000.00819.76
8.2.50.0030.00518.07
8.2.40.0080.00018.16
8.2.30.0020.00518.03
8.2.20.0040.00419.41
8.2.10.0040.00418.87
8.2.00.0050.00219.31
8.1.340.0100.01022.23
8.1.330.0120.00816.32
8.1.320.0080.01015.96
8.1.310.0180.00018.07
8.1.300.0080.00817.95
8.1.290.0000.00930.84
8.1.280.0070.00725.92
8.1.270.0070.00024.01
8.1.260.0040.00426.35
8.1.250.0070.00028.09
8.1.240.0030.00722.67
8.1.230.0000.01119.01
8.1.220.0040.00417.79
8.1.210.0000.00818.77
8.1.200.0000.00917.36
8.1.190.0040.00417.13
8.1.180.0000.00818.10
8.1.170.0080.00018.75
8.1.160.0040.00418.96
8.1.150.0040.00418.66
8.1.140.0000.00717.47
8.1.130.0050.00318.79
8.1.120.0040.00417.46
8.1.110.0040.00417.40
8.1.100.0000.00717.44
8.1.90.0070.00017.48
8.1.80.0030.00617.41
8.1.70.0030.00317.41
8.1.60.0050.00317.47
8.1.50.0030.00617.42
8.1.40.0050.00217.52
8.1.30.0060.00317.71
8.1.20.0040.00417.70
8.1.10.0000.00817.48
8.1.00.0030.00617.58
8.0.300.0050.00218.87
8.0.290.0000.00816.63
8.0.280.0050.00318.48
8.0.270.0040.00416.75
8.0.260.0060.00018.38
8.0.250.0040.00416.92
8.0.240.0000.00716.86
8.0.230.0000.00817.00
8.0.220.0040.00416.93
8.0.210.0040.00416.98
8.0.200.0000.00716.91
8.0.190.0000.00816.85
8.0.180.0030.00516.98
8.0.170.0000.00816.91
8.0.160.0040.00416.75
8.0.150.0030.00316.77
8.0.140.0030.00616.87
8.0.130.0040.00413.35
8.0.120.0050.00316.87
8.0.110.0000.00916.73
8.0.100.0060.00316.84
8.0.90.0030.00616.81
8.0.80.0060.00316.89
8.0.70.0000.00916.82
8.0.60.0040.00416.74
8.0.50.0050.00316.89
8.0.30.0040.00416.91
8.0.20.0030.00516.95
8.0.10.0080.00016.95
8.0.00.0080.00017.16
7.4.330.0040.00015.55
7.4.320.0060.00016.67
7.4.300.0000.00616.63
7.4.290.0000.00816.58
7.4.280.0030.00616.52
7.4.270.0030.00316.39
7.4.260.0030.00313.19
7.4.250.0050.00316.57
7.4.240.0040.00416.53
7.4.230.0050.00216.45
7.4.220.0000.00816.38
7.4.210.0040.00416.45
7.4.200.0000.00716.39
7.4.190.0000.00816.48
7.4.180.0040.00416.71
7.4.160.0040.00416.63
7.4.150.0000.00816.44
7.4.140.0030.00616.42
7.4.130.0050.00316.50
7.4.120.0050.00216.51
7.4.110.0000.00716.45
7.4.100.0000.00716.41
7.4.90.0030.00616.41
7.4.80.0000.00816.46
7.4.70.0040.00416.48
7.4.60.0050.00216.57
7.4.50.0070.00016.42
7.4.40.0000.00816.34
7.4.30.0040.00416.40
7.4.20.0000.00816.46
7.4.10.0000.00816.49
7.4.00.0040.00416.43
7.3.330.0040.00416.31
7.3.320.0050.00013.22
7.3.310.0000.00816.16
7.3.300.0070.00016.28
7.3.290.0030.00516.30
7.3.280.0030.00616.30
7.3.270.0050.00316.39
7.3.260.0030.00516.35
7.3.250.0030.00616.21
7.3.240.0030.00516.23
7.3.230.0040.00416.42
7.3.220.0030.00516.14
7.3.210.0080.00016.13
7.3.200.0090.00016.30
7.3.190.0040.00416.42
7.3.180.0060.00316.25
7.3.170.0040.00416.27
7.3.160.0000.00816.23
7.3.150.0000.00916.14
7.3.140.0070.00016.27
7.3.130.0080.00016.14
7.3.120.0030.00616.37
7.3.110.0060.00316.06
7.3.100.0030.00516.21
7.3.90.0030.00616.56
7.3.80.0000.00716.34
7.3.70.0030.00616.35
7.3.60.0030.00716.43
7.3.50.0050.00416.45
7.3.40.0030.00616.38
7.3.30.0050.00516.53
7.3.20.0070.00418.18
7.3.10.0090.00018.11
7.3.00.0000.00918.23

preferences:
828.57 ms | 1414 KiB | 5 Q