3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Simple array merging $array1 = [10, 50, 20, 40, 30]; $array2 = [1.0, 5.0, 2.0, 4.0, 3.0]; print_r(array_merge($array1, $array2)); // Sorting table-like arrays that has sorted by key elements $table1 = [ '2011:london' => ['city' => 'London', 'year' => 2011, 'birthrate' => 'over9000'], '2012:birmingham' => ['city' => 'Birmingham', 'year' => 2012, 'birthrate' => 'wat'], '2013:london' => ['city' => 'London', 'year' => 2013, 'birthrate' => 'boo boo'] ]; $table2 = [ '2011:london' => ['city' => 'London', 'year' => 2011, 'comment' => 1], '2012:london' => ['city' => 'London', 'year' => 2012, 'comment' => 22], '2014:london' => ['city' => 'London', 'year' => 2014, 'comment' => 333] ]; print_r(array_linear_merge($table1, $table2)); print_r(array_linear_merge2($table1, $table2)); // New func for merging sorted by unique key table-like arrays! // Complexity O(m+n), where m and n are sizes of each array. function array_linear_merge($array1, $array2) { $iterator1 = new ArrayIterator($array1); $iterator2 = new ArrayIterator($array2); $result = []; while ($iterator1->valid() && $iterator2->valid()) { switch(sign(strcmp($iterator1->key(), $iterator2->key()))) { case 1: $result[] = $iterator2->current(); $iterator2->next(); break; case 0: $result[] = array_merge($iterator1->current(), $iterator2->current()); $iterator1->next(); $iterator2->next(); break; case -1: $result[] = $iterator1->current(); $iterator1->next(); break; } } if (!$iterator1->valid()) { $iterator1 = $iterator2; } while ($iterator1->valid()) { $result[] = $iterator1->current(); $iterator1->next(); } return $result; } function array_linear_merge2($array1, $array2) { reset($array1); reset($array2); $result = []; while (current($array1) !== false && current($array2) !== false) { switch(sign(strcmp(key($array1), key($array2)))) { case 1: $result[] = current($array2); next($array2); break; case 0: $result[] = array_merge(current($array1), current($array2)); next($array1); next($array2); break; case -1: $result[] = current($array1); next($array1); break; } } while ($next = next($array1)) { $result[] = $next; } while ($next = next($array2)) { $result[] = $next; } return $result; } function sign($number) { return ($number > 0) - ($number < 0); }

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.0070.00716.75
8.3.50.0020.01322.93
8.3.40.0210.00018.79
8.3.30.0070.00719.04
8.3.20.0080.00020.20
8.3.10.0050.00323.48
8.3.00.0050.00317.75
8.2.180.0110.01116.63
8.2.170.0120.00322.96
8.2.160.0040.01120.52
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0030.00626.16
8.2.120.0040.00421.00
8.2.110.0030.00722.19
8.2.100.0070.00418.03
8.2.90.0050.00319.19
8.2.80.0050.00317.97
8.2.70.0060.00617.59
8.2.60.0000.00918.05
8.2.50.0090.00018.07
8.2.40.0040.00418.25
8.2.30.0050.00318.16
8.2.20.0070.00017.91
8.2.10.0040.00418.11
8.2.00.0000.00717.83
8.1.280.0070.00725.92
8.1.270.0110.00723.79
8.1.260.0050.00326.35
8.1.250.0000.00828.09
8.1.240.0060.00323.81
8.1.230.0110.00019.16
8.1.220.0040.00417.79
8.1.210.0080.00018.77
8.1.200.0000.00917.22
8.1.190.0030.00617.22
8.1.180.0000.00818.10
8.1.170.0040.00418.56
8.1.160.0040.00421.96
8.1.150.0040.00418.92
8.1.140.0040.00417.44
8.1.130.0060.00317.86
8.1.120.0030.00517.47
8.1.110.0050.00317.50
8.1.100.0000.00717.56
8.1.90.0040.00417.52
8.1.80.0040.00417.39
8.1.70.0070.00017.46
8.1.60.0000.00817.61
8.1.50.0000.00817.54
8.1.40.0050.00517.46
8.1.30.0030.00517.73
8.1.20.0000.00817.64
8.1.10.0000.00717.63
8.1.00.0040.00417.58
8.0.300.0070.00018.77
8.0.290.0050.00216.88
8.0.280.0000.00718.47
8.0.270.0040.00417.21
8.0.260.0000.00717.33
8.0.250.0030.00317.07
8.0.240.0030.00317.07
8.0.230.0080.00017.09
8.0.220.0040.00416.89
8.0.210.0040.00417.04
8.0.200.0070.00016.97
8.0.190.0030.00617.03
8.0.180.0040.00417.05
8.0.170.0000.00816.91
8.0.160.0040.00416.93
8.0.150.0000.00716.89
8.0.140.0080.00016.91
8.0.130.0030.00313.41
8.0.120.0080.00016.92
8.0.110.0040.00417.03
8.0.100.0040.00416.98
8.0.90.0040.00416.77
8.0.80.0060.00916.96
8.0.70.0070.00016.86
8.0.60.0040.00417.02
8.0.50.0040.00416.97
8.0.30.0120.00917.12
8.0.20.0090.01117.40
8.0.10.0090.00017.05
8.0.00.0090.00817.08
7.4.330.0050.00015.00
7.4.320.0070.00016.64
7.4.300.0060.00016.52
7.4.290.0050.00316.53
7.4.280.0060.00316.52
7.4.270.0000.00616.46
7.4.260.0030.00316.41
7.4.250.0070.00016.62
7.4.240.0020.00516.47
7.4.230.0070.00016.64
7.4.220.0070.01516.43
7.4.210.0090.00616.66
7.4.200.0000.00916.67
7.4.160.0280.00916.46
7.4.150.0140.00317.40
7.4.140.0050.01217.86
7.4.130.0030.01416.57
7.4.120.0150.00416.53
7.4.110.0130.00316.58
7.4.100.0060.01216.59
7.4.90.0090.00816.48
7.4.80.0180.00316.51
7.4.70.0070.01116.42
7.4.60.0090.01016.33
7.4.50.0090.00516.47
7.4.40.0130.00316.48
7.4.30.0160.00316.16
7.4.20.0170.00316.38
7.4.10.0100.00716.24
7.4.00.0110.00615.72
7.3.330.0030.00313.41
7.3.320.0060.00013.39
7.3.310.0040.00416.41
7.3.300.0030.00516.30
7.3.290.0030.01316.41
7.3.280.0100.00716.41
7.3.270.0070.01117.40
7.3.260.0100.00716.39
7.3.250.0130.00616.49
7.3.240.0100.00716.45
7.3.230.0070.01016.41
7.3.210.0150.00616.39
7.3.200.0090.01219.39
7.3.190.0070.01016.50
7.3.180.0080.00816.49
7.3.170.0090.00616.27
7.3.160.0120.00416.21
7.3.150.0060.00916.16
7.3.140.0080.00816.53
7.3.130.0100.00616.47
7.3.120.0100.00815.53
7.3.110.0050.01315.60
7.3.100.0050.01015.51
7.3.90.0080.00615.63
7.3.80.0040.01315.61
7.3.70.0080.00915.68
7.3.60.0130.00615.49
7.3.50.0130.00715.55
7.3.40.0070.01415.55
7.3.30.0090.00715.51
7.3.20.0120.01116.48
7.3.10.0090.00916.67
7.3.00.0090.00716.57
7.2.330.0060.01216.83
7.2.320.0040.01716.73
7.2.310.0070.01016.87
7.2.300.0100.00716.59
7.2.290.0120.00616.79
7.2.280.0120.00616.41
7.2.270.0120.00916.48
7.2.260.0170.00016.70
7.2.250.0080.00915.87
7.2.240.0060.01315.89
7.2.230.0060.01115.90
7.2.220.0070.01015.87
7.2.210.0090.00915.68
7.2.200.0070.01115.79
7.2.190.0130.00815.80
7.2.180.0070.01115.77
7.2.170.0110.00815.92
7.2.160.0150.00616.58
7.2.150.0050.01516.63
7.2.140.0120.01016.64
7.2.130.0090.00716.80
7.2.120.0040.01216.78
7.2.110.0130.00116.68
7.2.100.0160.00216.53
7.2.90.0080.00716.74
7.2.80.0080.00716.93
7.2.70.0050.01316.70
7.2.60.0040.01116.71
7.2.50.0060.01116.67
7.2.40.0090.00516.61
7.2.30.0070.01016.67
7.2.20.0070.01016.76
7.2.10.0060.00916.73
7.2.00.0060.01017.52
7.1.330.0090.01015.72
7.1.320.0060.00915.62
7.1.310.0090.00715.58
7.1.300.0100.01115.57
7.1.290.0060.01415.49
7.1.280.0090.00815.56
7.1.270.0080.00815.55
7.1.260.0140.00715.58
7.1.250.0100.00415.58
7.1.240.0080.01115.47
7.1.230.0030.01015.57
7.1.220.0050.00915.57
7.1.210.0050.00915.58
7.1.200.0060.00915.68
7.1.190.0100.01015.74
7.1.180.0060.01115.51
7.1.170.0070.01015.57
7.1.160.0090.00715.50
7.1.150.0050.00915.55
7.1.140.0080.00915.61
7.1.130.0090.00515.67
7.1.120.0070.00715.62
7.1.110.0050.00915.68
7.1.100.0070.01216.46
7.1.90.0070.00915.45
7.1.80.0080.00715.61
7.1.70.0060.00815.97
7.1.60.0100.00716.91
7.1.50.0070.00916.19
7.1.40.0060.00815.68
7.1.30.0070.00715.56
7.1.20.0060.00815.64
7.1.10.0060.00815.61
7.1.00.0060.02917.87
7.0.330.0100.00615.28
7.0.320.0070.00915.23
7.0.310.0100.00515.26
7.0.300.0070.00815.16
7.0.290.0070.00815.30
7.0.280.0110.00715.34
7.0.270.0110.00515.25
7.0.260.0110.00515.21
7.0.250.0140.00215.46
7.0.240.0060.01215.20
7.0.230.0080.01115.34
7.0.220.0070.00815.31
7.0.210.0100.00615.37
7.0.200.0020.01115.69
7.0.190.0070.00615.29
7.0.180.0060.01315.30
7.0.170.0020.01315.43
7.0.160.0040.01315.31
7.0.150.0090.00815.25
7.0.140.0100.02617.56
7.0.130.0100.00915.31
7.0.120.0110.00415.32
7.0.110.0110.00515.19
7.0.100.0100.00515.25
7.0.90.0050.01015.10
7.0.80.0070.00815.21
7.0.70.0070.01015.20
7.0.60.0130.03116.85
7.0.50.0080.03416.14
7.0.40.0080.02416.26
7.0.30.0110.02216.22
7.0.20.0130.02116.12
7.0.10.0080.02916.28
7.0.00.0090.03316.29
5.6.400.0140.01215.93
5.6.390.0060.01616.04
5.6.380.0130.00515.27
5.6.370.0110.00615.06
5.6.360.0080.01015.10
5.6.350.0040.01015.14
5.6.340.0070.01115.30
5.6.330.0060.01315.40
5.6.320.0120.00515.21
5.6.310.0050.01415.21
5.6.300.0070.00915.13
5.6.290.0110.00515.12
5.6.280.0100.02617.17
5.6.270.0090.00815.16
5.6.260.0100.00614.99
5.6.250.0090.00715.28
5.6.240.0130.00615.10
5.6.230.0050.01115.22
5.6.220.0080.01115.26
5.6.210.0070.03517.04
5.6.200.0070.03216.24
5.6.190.0060.02116.95
5.6.180.0110.02116.94
5.6.170.0180.02716.98
5.6.160.0070.03516.89
5.6.150.0060.03716.13
5.6.140.0070.03216.22
5.6.130.0120.02916.08
5.6.120.0080.01917.03
5.6.110.0090.02917.01
5.6.100.0100.02717.06
5.6.90.0100.02417.12
5.6.80.0040.02216.91
5.6.70.0060.01115.03
5.6.60.0080.00914.98
5.6.50.0090.00915.08
5.6.40.0110.00515.09
5.6.30.0070.00914.78
5.6.20.0100.00515.18
5.6.10.0100.00715.06
5.6.00.0050.01315.02
5.5.380.0040.01013.42
5.5.370.0070.00813.68
5.5.360.0090.00613.48
5.5.350.0040.03015.79
5.5.340.0080.02314.93
5.5.330.0070.02115.75
5.5.320.0130.01915.85
5.5.310.0150.02015.87
5.5.300.0060.03015.04
5.5.290.0110.02714.96
5.5.280.0100.02816.01
5.5.270.0070.02416.07
5.5.260.0060.03515.96
5.5.250.0050.02015.84
5.5.240.0140.02315.76
5.5.230.0050.01213.60
5.5.220.0150.00413.54
5.5.210.0050.01113.38
5.5.200.0050.00813.47
5.5.190.0030.01313.44
5.5.180.0140.00413.55
5.5.170.0110.00713.32
5.5.160.0080.00613.31
5.5.150.0060.01213.55
5.5.140.0070.00813.22
5.5.130.0080.00813.29
5.5.120.0110.00913.48
5.5.110.0070.00913.47
5.5.100.0090.00613.50
5.5.90.0090.00813.41
5.5.80.0020.01413.53
5.5.70.0110.00613.56
5.5.60.0090.00713.58
5.5.50.0090.00713.62
5.5.40.0050.01113.60
5.5.30.0080.00913.33
5.5.20.0060.01013.51
5.5.10.0070.00713.39
5.5.00.0050.01013.27
5.4.450.0100.01814.36
5.4.440.0170.02014.26
5.4.430.0140.02014.43
5.4.420.0110.01814.36
5.4.410.0160.01814.43
5.4.400.0130.01714.42
5.4.390.0030.02514.45
5.4.380.0230.01814.22
5.4.370.0210.02614.05
5.4.360.0200.02714.22
5.4.350.0190.02014.24
5.4.340.0180.02514.14
5.4.330.0070.00711.76
5.4.320.0080.01512.02
5.4.310.0090.01512.19
5.4.300.0100.01512.10
5.4.290.0090.01411.96
5.4.280.0060.01911.96
5.4.270.0060.01812.09
5.4.260.0050.01812.12
5.4.250.0070.01812.04
5.4.240.0070.01512.02
5.4.230.0070.01712.11
5.4.220.0040.02212.04
5.4.210.0070.01612.03
5.4.200.0110.01512.11
5.4.190.0050.01912.09
5.4.180.0090.01512.06
5.4.170.0080.01512.16
5.4.160.0110.01311.96
5.4.150.0050.01912.16
5.4.140.0100.01311.98
5.4.130.0090.01411.97
5.4.120.0050.02011.90
5.4.110.0030.02212.18
5.4.100.0060.02112.03
5.4.90.0070.01611.93
5.4.80.0100.01811.89
5.4.70.0060.01611.91
5.4.60.0050.01811.90
5.4.50.0070.01811.91
5.4.40.0090.01512.03
5.4.30.0060.01912.08
5.4.20.0070.01811.94
5.4.10.0050.01811.93
5.4.00.0070.01811.79
5.3.290.0080.01512.19
5.3.280.0070.01712.16
5.3.270.0050.01612.14
5.3.260.0070.01512.09
5.3.250.0020.02012.19
5.3.240.0050.01512.09
5.3.230.0040.01812.13
5.3.220.0060.01612.06
5.3.210.0010.02112.10
5.3.200.0080.01412.12
5.3.190.0080.01312.13
5.3.180.0030.01812.12
5.3.170.0010.02012.15
5.3.160.0050.01712.12
5.3.150.0050.01712.12
5.3.140.0060.01412.15
5.3.130.0040.01812.09
5.3.120.0050.01712.15
5.3.110.0070.01612.11
5.3.100.0050.01611.94
5.3.90.0070.01311.90
5.3.80.0050.01611.93
5.3.70.0060.01611.94
5.3.60.0080.01411.89
5.3.50.0080.01611.87
5.3.40.0030.01911.87
5.3.30.0060.01711.80
5.3.20.0070.01411.77
5.3.10.0050.01811.72
5.3.00.0040.01711.68
5.2.170.0070.01110.63
5.2.160.0050.01410.61
5.2.150.0060.01210.70
5.2.140.0050.01110.60
5.2.130.0030.01410.59
5.2.120.0060.01410.61
5.2.110.0050.01310.59
5.2.100.0070.01410.58
5.2.90.0030.01610.66
5.2.80.0040.01610.57
5.2.70.0070.01410.55
5.2.60.0040.01610.52
5.2.50.0030.01410.55
5.2.40.0040.01310.54
5.2.30.0070.01310.51
5.2.20.0040.01410.50
5.2.10.0030.01310.47
5.2.00.0070.01310.36
5.1.60.0040.01110.00
5.1.50.0040.0119.94
5.1.40.0040.0129.97
5.1.30.0050.01210.09
5.1.20.0030.01410.05
5.1.10.0040.01410.06
5.1.00.0040.0129.90
5.0.50.0030.0119.22
5.0.40.0020.0149.17
5.0.30.0060.0119.11
5.0.20.0020.0119.10
5.0.10.0030.0109.09
5.0.00.0030.0139.09
4.4.90.0020.0088.60
4.4.80.0050.0088.60
4.4.70.0030.0088.60
4.4.60.0030.0078.60
4.4.50.0030.0078.60
4.4.40.0020.0118.58
4.4.30.0040.0058.60
4.4.20.0040.0058.63
4.4.10.0020.0078.63
4.4.00.0020.0118.60
4.3.110.0020.0078.57
4.3.100.0040.0058.57
4.3.90.0040.0068.56
4.3.80.0020.0108.54
4.3.70.0020.0068.56
4.3.60.0030.0088.55
4.3.50.0010.0098.55
4.3.40.0010.0168.53
4.3.30.0000.0098.11
4.3.20.0030.0068.10
4.3.10.0010.0078.09
4.3.00.0050.00712.34

preferences:
49.65 ms | 401 KiB | 5 Q