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($arrayLeft); $iterator2 = new ArrayIterator($arrayRight); $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.0130.00616.88
8.3.50.0060.01122.92
8.3.40.0040.01118.84
8.3.30.0140.00319.09
8.3.20.0060.00320.39
8.3.10.0080.00023.67
8.3.00.0060.00319.51
8.2.180.0120.00916.75
8.2.170.0080.00822.96
8.2.160.0080.00820.57
8.2.150.0040.00424.18
8.2.140.0090.00024.66
8.2.130.0160.00326.16
8.2.120.0040.00421.02
8.2.110.0080.00022.24
8.2.100.0040.00717.91
8.2.90.0000.00919.09
8.2.80.0000.00817.97
8.2.70.0040.00417.63
8.2.60.0000.00817.80
8.2.50.0040.00718.07
8.2.40.0050.00318.03
8.2.30.0040.00417.98
8.2.20.0050.00317.79
8.2.10.0060.00317.99
8.2.00.0040.00417.84
8.1.280.0110.00425.92
8.1.270.0040.00423.96
8.1.260.0040.00426.35
8.1.250.0000.00728.09
8.1.240.0050.00523.93
8.1.230.0070.00419.08
8.1.220.0000.00817.74
8.1.210.0000.00818.77
8.1.200.0100.00017.22
8.1.190.0000.00817.23
8.1.180.0080.00018.10
8.1.170.0000.00918.46
8.1.160.0000.00721.99
8.1.150.0040.00418.91
8.1.140.0070.00017.42
8.1.130.0000.00717.85
8.1.120.0050.00217.45
8.1.110.0000.00817.39
8.1.100.0030.00517.37
8.1.90.0000.01017.43
8.1.80.0000.00717.50
8.1.70.0050.00317.34
8.1.60.0080.00017.64
8.1.50.0060.00317.50
8.1.40.0060.00317.61
8.1.30.0030.00517.65
8.1.20.0050.00317.75
8.1.10.0000.00717.66
8.1.00.0040.00417.48
8.0.300.0040.00418.77
8.0.290.0040.00416.88
8.0.280.0070.00018.43
8.0.270.0030.00316.86
8.0.260.0060.00017.25
8.0.250.0000.00717.03
8.0.240.0000.00717.01
8.0.230.0030.00516.88
8.0.220.0000.00716.84
8.0.210.0000.00716.97
8.0.200.0000.00617.04
8.0.190.0040.00416.93
8.0.180.0000.00716.85
8.0.170.0080.00016.87
8.0.160.0070.00016.99
8.0.150.0000.00716.79
8.0.140.0040.00416.92
8.0.130.0030.00313.45
8.0.120.0000.00716.79
8.0.110.0000.00816.78
8.0.100.0000.00716.96
8.0.90.0030.00316.89
8.0.80.0120.00916.99
8.0.70.0040.00416.89
8.0.60.0000.00716.92
8.0.50.0000.00716.79
8.0.30.0070.01316.98
8.0.20.0060.01317.40
8.0.10.0070.00017.01
8.0.00.0120.00816.74
7.4.330.0020.00215.02
7.4.320.0000.00616.50
7.4.300.0070.00016.66
7.4.290.0030.00316.54
7.4.280.0090.00016.54
7.4.270.0040.00416.57
7.4.260.0030.00316.43
7.4.250.0040.00416.65
7.4.240.0080.00016.54
7.4.230.0000.00816.62
7.4.220.0090.00916.46
7.4.210.0090.00516.61
7.4.200.0080.00016.48
7.4.160.0070.01316.54
7.4.150.0100.00717.40
7.4.140.0060.01117.86
7.4.130.0080.00916.49
7.4.120.0060.01116.54
7.4.110.0060.01016.44
7.4.100.0130.00416.65
7.4.90.0100.00616.59
7.4.80.0110.00716.66
7.4.70.0140.00316.47
7.4.60.0110.00616.54
7.4.50.0090.00516.49
7.4.40.0000.01716.50
7.4.30.0120.00316.25
7.4.20.0100.00616.23
7.4.10.0130.00616.27
7.4.00.0110.00615.88
7.3.330.0030.00313.27
7.3.320.0050.00013.36
7.3.310.0070.00016.30
7.3.300.0070.00016.25
7.3.290.0100.01116.33
7.3.280.0060.01016.34
7.3.270.0120.00617.40
7.3.260.0090.00916.46
7.3.250.0130.00716.33
7.3.240.0100.00716.55
7.3.230.0070.01016.55
7.3.210.0090.00916.31
7.3.200.0140.00419.39
7.3.190.0080.00816.49
7.3.180.0090.00616.53
7.3.170.0060.00916.29
7.3.160.0050.01116.32
7.3.150.0060.01016.37
7.3.140.0030.01316.36
7.3.130.0090.00916.45
7.3.120.0090.00916.21
7.3.110.0180.00316.32
7.3.100.0160.00316.35
7.3.90.0090.00616.23
7.3.80.0040.01516.20
7.3.70.0120.00316.27
7.3.60.0100.00716.18
7.3.50.0040.01616.33
7.3.40.0080.00816.38
7.3.30.0070.01116.12
7.3.20.0060.01016.26
7.3.10.0090.00616.39
7.3.00.0090.00916.35
7.2.330.0070.01116.30
7.2.320.0060.01616.34
7.2.310.0140.00316.34
7.2.300.0100.00616.38
7.2.290.0060.01216.49
7.2.280.0060.01216.23
7.2.270.0120.00916.34
7.2.260.0190.00616.42
7.2.250.0080.01216.20
7.2.240.0120.00616.29
7.2.230.0130.00516.29
7.2.220.0000.01716.25
7.2.210.0120.00416.31
7.2.200.0090.00616.19
7.2.190.0000.01516.33
7.2.180.0120.00816.44
7.2.170.0070.01016.13
7.2.160.0070.01016.37
7.2.150.0060.01016.55
7.2.140.0060.01016.21
7.2.130.0030.01216.40
7.2.120.0100.00916.43
7.2.110.0080.00816.38
7.2.100.0030.01316.31
7.2.90.0130.00816.60
7.2.80.0110.00716.42
7.2.70.0370.00916.57
7.2.60.0080.00716.36
7.2.50.0100.00716.36
7.2.40.0120.00616.27
7.2.30.0180.00016.39
7.2.20.0100.01016.17
7.2.10.0150.00816.48
7.2.00.0130.00717.77
7.1.330.0070.00715.36
7.1.320.0150.00015.32
7.1.310.0040.01615.30
7.1.300.0120.00415.13
7.1.290.0100.01015.28
7.1.280.0080.00915.39
7.1.270.0080.01115.46
7.1.260.0100.00615.42
7.1.250.0070.01015.52
7.1.240.0050.01515.30
7.1.230.0070.01015.29
7.1.220.0040.01315.57
7.1.210.0090.00615.15
7.1.200.0110.00515.42
7.1.190.0080.00815.54
7.1.180.0060.01015.39
7.1.170.0100.00515.37
7.1.160.0080.00815.34
7.1.150.0090.00615.54
7.1.140.0070.01015.48
7.1.130.0100.00715.47
7.1.120.0090.00615.34
7.1.110.0070.01015.54
7.1.100.0080.00716.76
7.1.90.0040.01215.36
7.1.80.0090.01215.31
7.1.70.0080.00416.08
7.1.60.0070.01417.40
7.1.50.0110.00916.16
7.1.40.0030.01315.29
7.1.30.0090.00615.20
7.1.20.0030.01215.50
7.1.10.0110.01115.45
7.1.00.0090.04218.77
7.0.330.0150.00315.29
7.0.320.0150.00315.11
7.0.310.0100.00815.09
7.0.300.0080.00814.86
7.0.290.0060.01215.08
7.0.280.0210.00415.32
7.0.270.0090.00915.11
7.0.260.0070.01015.13
7.0.250.0190.00315.16
7.0.240.0110.00815.16
7.0.230.0090.01214.97
7.0.220.0180.00414.89
7.0.210.0120.00615.33
7.0.200.0050.00715.86
7.0.190.0030.01714.95
7.0.180.0220.00614.95
7.0.170.0180.00015.19
7.0.160.0060.01315.12
7.0.150.0120.00915.19
7.0.140.0090.04018.55
7.0.130.0140.00615.09
7.0.120.0160.01015.04
7.0.110.0130.01114.85
7.0.100.0120.00715.05
7.0.90.0170.00414.97
7.0.80.0090.01315.23
7.0.70.0160.00515.04
7.0.60.0060.02417.38
7.0.50.0070.04716.56
7.0.40.0080.02817.60
7.0.30.0200.04017.65
7.0.20.0070.03017.80
7.0.10.0060.03117.65
7.0.00.0050.05017.59
5.6.400.0070.01416.03
5.6.390.0180.00316.03
5.6.380.0080.01215.95
5.6.370.0110.01416.08
5.6.360.0110.00816.06
5.6.350.0150.00915.88
5.6.340.0060.01215.96
5.6.330.0040.01516.04
5.6.320.0060.01215.71
5.6.310.0150.00315.75
5.6.300.0110.01415.88
5.6.290.0100.01316.07
5.6.280.0050.04318.35
5.6.270.0160.00415.86
5.6.260.0080.01215.81
5.6.250.0150.00915.57
5.6.240.0030.02315.57
5.6.230.0080.01315.71
5.6.220.0040.01615.64
5.6.210.0140.03718.09
5.6.200.0060.03016.94
5.6.190.0100.03018.16
5.6.180.1800.02618.26
5.6.170.0210.04218.09
5.6.160.0120.03618.09
5.6.150.0070.04817.09
5.6.140.0100.04416.98
5.6.130.0080.02816.90
5.6.120.0070.03518.40
5.6.110.0080.05118.36
5.6.100.0070.04718.36
5.6.90.0120.04018.32
5.6.80.0100.03718.09
5.6.70.1970.02818.13
5.6.60.0120.00615.56
5.6.50.0080.01115.70
5.6.40.0090.00915.68
5.6.30.0080.01115.89
5.6.20.0070.01115.81
5.6.10.0060.01215.84
5.6.00.0040.01615.80
5.5.380.0150.00615.67
5.5.370.0160.01215.79
5.5.360.0130.00715.53
5.5.350.0140.04018.04
5.5.340.0110.04416.74
5.5.330.0050.04918.02
5.5.320.0250.03618.09
5.5.310.0190.03118.04
5.5.300.0120.04016.82
5.5.290.0070.04116.82
5.5.280.0060.02618.24
5.5.270.0100.02518.25
5.5.260.0090.04918.14
5.5.250.0090.05018.15
5.5.240.0130.04318.08
5.5.230.0150.00315.50
5.5.220.0110.00915.80
5.5.210.0140.00515.49
5.5.200.0070.01315.64
5.5.190.0140.00515.60
5.5.180.0120.00815.74
5.5.170.0040.01815.82
5.5.160.0130.01315.76
5.5.150.0080.01115.79
5.5.140.0040.01615.45
5.5.130.0110.00715.66
5.5.120.0080.01115.66
5.5.110.0150.00315.70
5.5.100.0070.01115.52
5.5.90.0080.01615.54
5.5.80.0040.02115.96
5.5.70.0130.00615.48
5.5.60.0100.00915.78
5.5.50.0130.00915.67
5.5.40.0030.02115.70
5.5.30.0090.01515.51
5.5.20.0060.01315.65
5.5.10.0060.01415.69
5.5.00.0050.01415.50
5.4.450.0120.02615.96
5.4.440.0290.02216.03
5.4.430.0130.02915.78
5.4.420.0140.02615.98
5.4.410.0160.03216.04
5.4.400.0230.03015.66
5.4.390.0180.02115.84
5.4.380.0580.02515.64
5.4.370.0180.03215.50
5.4.360.0210.03115.71
5.4.350.0230.02615.76
5.4.340.0200.02915.69
5.4.330.0030.01012.21
5.4.320.0050.02412.50
5.4.310.0050.02612.46
5.4.300.0060.02312.57
5.4.290.0100.02212.40
5.4.280.0040.03112.43
5.4.270.0100.02812.57
5.4.260.0110.02712.52
5.4.250.0120.02912.43
5.4.240.0060.03212.39
5.4.230.0080.02912.41
5.4.220.0070.02812.43
5.4.210.0060.02312.49
5.4.200.0060.02512.44
5.4.190.0080.02112.27
5.4.180.0070.02112.42
5.4.170.0070.02112.36
5.4.160.0080.02012.51
5.4.150.0100.02112.52
5.4.140.0100.01912.29
5.4.130.0050.02312.32
5.4.120.0090.01912.27
5.4.110.0110.02012.30
5.4.100.0090.01912.29
5.4.90.0070.02412.29
5.4.80.0070.03012.18
5.4.70.0060.02712.20
5.4.60.0070.02212.34
5.4.50.0040.02412.31
5.4.40.0060.02112.24
5.4.30.0060.02212.25
5.4.20.0080.02112.28
5.4.10.0100.01812.36
5.4.00.0060.02311.89
5.3.290.0060.02612.83
5.3.280.0060.02312.70
5.3.270.0080.02512.75
5.3.260.0080.03012.69
5.3.250.0050.02612.69
5.3.240.0080.02212.63
5.3.230.0050.02512.69
5.3.220.0080.02712.74
5.3.210.0100.02312.63
5.3.200.0070.02112.63
5.3.190.0100.02012.65
5.3.180.0060.02212.81
5.3.170.0090.02012.75
5.3.160.0070.02312.69
5.3.150.0130.01712.82
5.3.140.0060.02312.71
5.3.130.0070.02212.71
5.3.120.0090.02112.76
5.3.110.0080.02312.68
5.3.100.0050.02412.45
5.3.90.0090.02012.44
5.3.80.0070.02212.43
5.3.70.0060.02512.36
5.3.60.0050.02312.39
5.3.50.0090.02012.32
5.3.40.0050.02412.38
5.3.30.0100.02012.30
5.3.20.0060.02512.22
5.3.10.0070.02312.08
5.3.00.0090.02012.05
5.2.170.0050.01910.46
5.2.160.0090.01510.52
5.2.150.0020.02110.50
5.2.140.0040.02110.51
5.2.130.0030.02210.43
5.2.120.0060.01910.45
5.2.110.0030.02210.45
5.2.100.0050.02010.43
5.2.90.0070.01610.46
5.2.80.0090.01710.43
5.2.70.0050.01910.37
5.2.60.0070.01710.35
5.2.50.0070.01810.45
5.2.40.0080.01710.41
5.2.30.0050.02010.32
5.2.20.0030.01910.25
5.2.10.0070.01710.26
5.2.00.0080.01710.16
5.1.60.0040.0169.42
5.1.50.0050.0169.46
5.1.40.0060.0149.45
5.1.30.0040.0169.73
5.1.20.0070.0159.65
5.1.10.0040.0179.48
5.1.00.0050.0169.57
5.0.50.0040.0138.38
5.0.40.0050.0128.32
5.0.30.0040.0228.21
5.0.20.0030.0138.20
5.0.10.0030.0148.19
5.0.00.0040.0178.19
4.4.90.0020.0107.46
4.4.80.0020.0097.45
4.4.70.0020.0097.45
4.4.60.0020.0107.45
4.4.50.0010.0127.46
4.4.40.0050.0137.42
4.4.30.0030.0097.45
4.4.20.0030.0097.49
4.4.10.0020.0127.49
4.4.00.0050.0127.45
4.3.110.0030.0097.41
4.3.100.0030.0087.40
4.3.90.0020.0097.38
4.3.80.0020.0147.36
4.3.70.0030.0087.38
4.3.60.0020.0097.38
4.3.50.0020.0117.38
4.3.40.0030.0157.34
4.3.30.0030.0116.71
4.3.20.0020.0126.70
4.3.10.0030.0116.68
4.3.00.0040.00813.06

preferences:
39.25 ms | 401 KiB | 5 Q