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)); // 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 sign($number) { return ($n > 0) - ($n < 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.0160.00316.60
8.3.50.0130.00823.05
8.3.40.0180.00318.79
8.3.30.0140.00019.16
8.3.20.0000.01020.34
8.3.10.0040.00423.65
8.3.00.0040.00417.50
8.2.180.0100.01016.63
8.2.170.0040.01122.96
8.2.160.0070.00720.53
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0030.01026.16
8.2.120.0040.00421.16
8.2.110.0060.00322.21
8.2.100.0090.00317.84
8.2.90.0000.00819.34
8.2.80.0000.00817.97
8.2.70.0040.00417.63
8.2.60.0050.00318.05
8.2.50.0000.00818.07
8.2.40.0080.00018.28
8.2.30.0000.00718.17
8.2.20.0000.00717.73
8.2.10.0000.00818.22
8.2.00.0050.00317.84
8.1.280.0110.00425.92
8.1.270.0140.00423.97
8.1.260.0030.00326.35
8.1.250.0080.00028.09
8.1.240.0090.00023.90
8.1.230.0060.00619.16
8.1.220.0000.00817.79
8.1.210.0080.00018.77
8.1.200.0060.00317.35
8.1.190.0040.00417.35
8.1.180.0000.00818.10
8.1.170.0000.00818.64
8.1.160.0040.00421.93
8.1.150.0000.00818.94
8.1.140.0040.00417.48
8.1.130.0030.00517.79
8.1.120.0040.00417.54
8.1.110.0040.00417.54
8.1.100.0040.00317.48
8.1.90.0000.00817.38
8.1.80.0000.00717.40
8.1.70.0000.00717.41
8.1.60.0060.00317.51
8.1.50.0070.00017.54
8.1.40.0000.00817.61
8.1.30.0000.00917.54
8.1.20.0050.00217.69
8.1.10.0000.00817.50
8.1.00.0030.00617.62
8.0.300.0070.00018.77
8.0.290.0070.00016.88
8.0.280.0000.00718.55
8.0.270.0040.00416.93
8.0.260.0000.00617.30
8.0.250.0030.00317.11
8.0.240.0030.00317.04
8.0.230.0000.00817.03
8.0.220.0070.00016.97
8.0.210.0000.00716.95
8.0.200.0000.00617.10
8.0.190.0030.00317.10
8.0.180.0040.00417.02
8.0.170.0040.00416.93
8.0.160.0040.00417.06
8.0.150.0030.00517.02
8.0.140.0070.00016.86
8.0.130.0000.00713.46
8.0.120.0000.00716.84
8.0.110.0040.00417.03
8.0.100.0040.00416.91
8.0.90.0030.00316.82
8.0.80.0060.01116.98
8.0.70.0000.00816.98
8.0.60.0070.00016.98
8.0.50.0020.00516.86
8.0.30.0110.00817.19
8.0.20.0120.01217.40
8.0.10.0040.00416.93
8.0.00.0130.00717.02
7.4.330.0000.00515.00
7.4.320.0060.00016.56
7.4.300.0000.00616.54
7.4.290.0030.00316.50
7.4.280.0000.00816.52
7.4.270.0050.00316.59
7.4.260.0030.00316.55
7.4.250.0040.00416.50
7.4.240.0050.00216.57
7.4.230.0030.00316.62
7.4.220.0130.00416.58
7.4.210.0070.00716.70
7.4.200.0030.00316.64
7.4.160.0040.01616.46
7.4.150.0130.01017.40
7.4.140.0110.00517.86
7.4.130.0080.00916.56
7.4.120.0130.00316.66
7.4.110.0100.00716.64
7.4.100.0070.01116.60
7.4.90.0130.00316.48
7.4.80.0040.01416.70
7.4.70.0090.01216.45
7.4.60.0110.00816.49
7.4.50.0070.00816.46
7.4.40.0030.01416.37
7.4.30.0100.00616.58
7.4.20.0100.00616.33
7.4.10.0070.01116.00
7.4.00.0100.00715.67
7.3.330.0000.00513.39
7.3.320.0050.00013.27
7.3.310.0070.00016.27
7.3.300.0000.00716.37
7.3.290.0140.00716.45
7.3.280.0100.00616.48
7.3.270.0060.01317.40
7.3.260.0000.01916.45
7.3.250.0110.00616.59
7.3.240.0170.00016.44
7.3.230.0070.01016.49
7.3.210.0170.00016.53
7.3.200.0160.00619.39
7.3.190.0030.01716.57
7.3.180.0040.01216.51
7.3.170.0060.01516.61
7.3.160.0070.01016.48
7.3.150.0110.00516.23
7.3.140.0080.01216.49
7.3.130.0060.01015.77
7.3.120.0060.01015.45
7.3.110.0090.00815.45
7.3.100.0090.00615.35
7.3.90.0050.00915.53
7.3.80.0070.01015.30
7.3.70.0070.00815.32
7.3.60.0100.00815.48
7.3.50.0050.01015.46
7.3.40.0090.00715.32
7.3.30.0040.00915.33
7.3.20.0140.00816.56
7.3.10.0090.00916.53
7.3.00.0080.00816.63
7.2.330.0150.00716.77
7.2.320.0150.00916.48
7.2.310.0170.00416.45
7.2.300.0160.00716.54
7.2.290.0110.00516.70
7.2.280.0130.00416.56
7.2.270.0060.01416.62
7.2.260.0070.01316.00
7.2.250.0080.01115.58
7.2.240.0080.01015.66
7.2.230.0090.00615.60
7.2.220.0060.00915.65
7.2.210.0070.00915.70
7.2.200.0100.00715.58
7.2.190.0090.00715.58
7.2.180.0110.00515.55
7.2.170.0070.00815.46
7.2.160.0060.00915.90
7.2.150.0060.01116.92
7.2.140.0110.00716.64
7.2.130.0100.00416.80
7.2.120.0070.01116.67
7.2.110.0100.00916.56
7.2.100.0110.00816.75
7.2.90.0090.01116.87
7.2.80.0090.00916.90
7.2.70.0100.00816.86
7.2.60.0100.00916.70
7.2.50.0100.00516.88
7.2.40.0110.00816.67
7.2.30.0120.00716.78
7.2.20.0130.00416.82
7.2.10.0070.00816.74
7.2.00.0070.00917.63
7.1.330.0070.00815.73
7.1.320.0040.01115.64
7.1.310.0040.00915.76
7.1.300.0080.00715.74
7.1.290.0090.00815.72
7.1.280.0060.01015.61
7.1.270.0070.01015.70
7.1.260.0070.00915.58
7.1.250.0080.00615.71
7.1.240.0100.00715.70
7.1.230.0080.01115.66
7.1.220.0090.00715.66
7.1.210.0110.00615.53
7.1.200.0110.00515.71
7.1.190.0130.00815.65
7.1.180.0080.00715.69
7.1.170.0100.00515.59
7.1.160.0150.00715.52
7.1.150.0100.00915.59
7.1.140.0090.00815.66
7.1.130.0100.00615.65
7.1.120.0080.00815.62
7.1.110.0120.00715.81
7.1.100.0090.00716.49
7.1.90.0060.00815.55
7.1.80.0140.00515.54
7.1.70.0090.00516.05
7.1.60.0090.00816.24
7.1.50.0090.01322.05
7.1.40.0060.00815.66
7.1.30.0090.00715.63
7.1.20.0070.01015.73
7.1.10.0080.00815.67
7.1.00.0090.02917.82
7.0.330.0090.00615.34
7.0.320.0060.00915.25
7.0.310.0110.00815.30
7.0.300.0100.00515.25
7.0.290.0120.00715.31
7.0.280.0100.00615.38
7.0.270.0070.00915.15
7.0.260.0140.00515.19
7.0.250.0090.00715.43
7.0.240.0050.01015.31
7.0.230.0100.00515.28
7.0.220.0130.00615.28
7.0.210.0070.01115.45
7.0.200.0060.01015.85
7.0.190.0050.01215.12
7.0.180.0050.00915.46
7.0.170.0090.00715.36
7.0.160.0080.01015.31
7.0.150.0090.00715.23
7.0.140.0090.02917.61
7.0.130.0150.01015.56
7.0.120.0050.01315.41
7.0.110.0100.00815.23
7.0.100.0130.00615.19
7.0.90.0120.00715.37
7.0.80.0070.00815.27
7.0.70.0120.00815.27
7.0.60.0080.01616.83
7.0.50.0100.02916.24
7.0.40.0070.02716.15
7.0.30.0250.03116.33
7.0.20.0170.03216.40
7.0.10.0080.03316.25
7.0.00.0050.02216.22
5.6.400.0100.00915.39
5.6.390.0090.01015.46
5.6.380.0120.00515.14
5.6.370.0100.01215.18
5.6.360.0050.01415.25
5.6.350.0100.01015.31
5.6.340.0080.01015.47
5.6.330.0060.01215.42
5.6.320.0120.00515.24
5.6.310.0110.00515.37
5.6.300.0120.00815.11
5.6.290.0100.00815.06
5.6.280.0090.02717.08
5.6.270.0090.01115.25
5.6.260.0090.00915.42
5.6.250.0060.00815.04
5.6.240.0110.00714.99
5.6.230.0050.01115.43
5.6.220.0120.00615.08
5.6.210.0090.03217.10
5.6.200.0090.03516.27
5.6.190.0070.03116.97
5.6.180.0150.03416.94
5.6.170.0140.02016.76
5.6.160.0120.03016.91
5.6.150.0070.03316.24
5.6.140.0110.01916.16
5.6.130.0080.01916.09
5.6.120.0080.03417.09
5.6.110.0100.03317.04
5.6.100.0090.02317.07
5.6.90.0120.02717.15
5.6.80.0100.02916.95
5.6.70.0060.01315.33
5.6.60.0100.00615.11
5.6.50.0120.00515.04
5.6.40.0130.00614.80
5.6.30.0140.00615.14
5.6.20.0110.00815.03
5.6.10.0120.01015.07
5.6.00.0100.00715.07
5.5.380.0090.00715.01
5.5.370.0120.00515.02
5.5.360.0060.01215.11
5.5.350.0100.03216.91
5.5.340.0070.02416.08
5.5.330.0090.03416.74
5.5.320.0150.02016.77
5.5.310.0150.01716.96
5.5.300.0120.02916.00
5.5.290.0050.03616.09
5.5.280.0030.03716.95
5.5.270.0060.03016.98
5.5.260.0090.03517.03
5.5.250.0120.03116.90
5.5.240.0080.03616.77
5.5.230.0100.00814.99
5.5.220.0120.00715.31
5.5.210.0130.00515.00
5.5.200.0080.01014.97
5.5.190.0060.00914.93
5.5.180.0090.01314.86
5.5.170.0110.01014.99
5.5.160.0050.01415.01
5.5.150.0090.00814.90
5.5.140.0130.00515.16
5.5.130.0100.00914.96
5.5.120.0110.00615.03
5.5.110.0080.00915.16
5.5.100.0050.01415.09
5.5.90.0060.01315.05
5.5.80.0100.00815.21
5.5.70.0130.00714.94
5.5.60.0110.00814.94
5.5.50.0110.00615.14
5.5.40.0170.00315.03
5.5.30.0140.00915.05
5.5.20.0110.00814.76
5.5.10.0050.01715.07
5.5.00.0040.01615.06
5.4.450.0230.02214.58
5.4.440.0090.01914.48
5.4.430.0110.02514.42
5.4.420.0160.01614.38
5.4.410.0260.01414.44
5.4.400.0250.01714.34
5.4.390.0170.01914.29
5.4.380.0160.02514.30
5.4.370.0210.02814.16
5.4.360.0170.02214.16
5.4.350.0160.03014.16
5.4.340.0170.02314.14
5.4.330.0090.00711.82
5.4.320.0100.01312.11
5.4.310.0080.01712.08
5.4.300.0090.01512.13
5.4.290.0060.01912.10
5.4.280.0060.01612.14
5.4.270.0070.01512.21
5.4.260.0090.01612.08
5.4.250.0080.01712.09
5.4.240.0090.01312.07
5.4.230.0080.01912.07
5.4.220.0090.01512.03
5.4.210.0060.01912.12
5.4.200.0100.02012.10
5.4.190.0090.02011.98
5.4.180.0080.01612.06
5.4.170.0080.01612.11
5.4.160.0060.01812.09
5.4.150.0070.01512.11
5.4.140.0060.01712.03
5.4.130.0050.01712.00
5.4.120.0090.01411.97
5.4.110.0040.02112.13
5.4.100.0060.01612.06
5.4.90.0060.02011.99
5.4.80.0070.01712.02
5.4.70.0070.01711.95
5.4.60.0040.01911.96
5.4.50.0090.01711.96
5.4.40.0050.02111.97
5.4.30.0080.01511.93
5.4.20.0080.01711.97
5.4.10.0050.01711.97
5.4.00.0070.01711.76
5.3.290.0060.02512.83
5.3.280.0090.01912.68
5.3.270.0060.02312.83
5.3.260.0120.01812.68
5.3.250.0050.02312.70
5.3.240.0080.02112.71
5.3.230.0030.02612.71
5.3.220.0080.02112.67
5.3.210.0050.02512.70
5.3.200.0050.02312.63
5.3.190.0080.02112.72
5.3.180.0060.02212.79
5.3.170.0060.02212.69
5.3.160.0080.02112.72
5.3.150.0070.02412.75
5.3.140.0090.02312.73
5.3.130.0030.03112.70
5.3.120.0070.02212.75
5.3.110.0060.02412.68
5.3.100.0040.02412.46
5.3.90.0090.02012.57
5.3.80.0030.02412.37
5.3.70.0070.02212.37
5.3.60.0060.02112.43
5.3.50.0050.02512.37
5.3.40.0090.02012.46
5.3.30.0070.02712.26
5.3.20.0090.02512.17
5.3.10.0090.02312.15
5.3.00.0100.02212.14
5.2.170.0030.02110.54
5.2.160.0050.01810.49
5.2.150.0080.02010.59
5.2.140.0060.02610.42
5.2.130.0140.01310.43
5.2.120.0090.02010.50
5.2.110.0070.01910.43
5.2.100.0090.01810.55
5.2.90.0090.01810.41
5.2.80.0030.02310.38
5.2.70.0070.01910.39
5.2.60.0100.01710.31
5.2.50.0080.01810.36
5.2.40.0100.01810.35
5.2.30.0100.01810.33
5.2.20.0070.02110.37
5.2.10.0080.01610.30
5.2.00.0040.01910.11
5.1.60.0070.0189.44
5.1.50.0050.0169.42
5.1.40.0050.0159.44
5.1.30.0050.0169.76
5.1.20.0050.0159.66
5.1.10.0080.0159.49
5.1.00.0060.0159.57
5.0.50.0070.0158.38
5.0.40.0070.0118.31
5.0.30.0040.0198.22
5.0.20.0060.0138.20
5.0.10.0060.0118.19
5.0.00.0030.0188.19
4.4.90.0020.0117.46
4.4.80.0050.0087.45
4.4.70.0020.0117.45
4.4.60.0060.0077.45
4.4.50.0040.0087.46
4.4.40.0030.0147.42
4.4.30.0030.0097.45
4.4.20.0040.0087.49
4.4.10.0040.0087.49
4.4.00.0020.0157.45
4.3.110.0050.0077.40
4.3.100.0030.0097.40
4.3.90.0030.0087.39
4.3.80.0040.0137.36
4.3.70.0010.0117.38
4.3.60.0030.0097.38
4.3.50.0050.0097.38
4.3.40.0020.0147.34
4.3.30.0010.0116.71
4.3.20.0040.0096.70
4.3.10.0020.0106.68
4.3.00.0080.00913.06

preferences:
45.83 ms | 401 KiB | 5 Q