3v4l.org

run code in 300+ PHP versions simultaneously
<?php function arrayMergeRecursiveDistinct(array $first, array $second) { foreach ($second as $idx => $value) { if (is_integer($idx)) { $first[] = $value; } else { if (!array_key_exists($idx, $first)) { $first[$idx] = $value; } else { if (is_array($value)) { $first[$idx] = arrayMergeRecursiveDistinct($first[$idx], $value); } else { $first[$idx] = $value; } } } } return $first; } $a = ['a' => [1,2,3], 'b' => ['c' => ['d' => 'e']]]; $b = ['a' => [2,3,4], 'b']; print_r(arrayMergeRecursiveDistinct($b, $a)); print_r(array_replace_recursive($b, $a));

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.0040.01118.27
8.3.50.0120.00522.16
8.3.40.0040.01118.79
8.3.30.0090.00619.04
8.3.20.0040.00420.34
8.3.10.0030.00620.38
8.3.00.0030.00519.25
8.2.180.0060.01116.63
8.2.170.0080.00622.96
8.2.160.0110.00420.35
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0020.00526.16
8.2.120.0060.00922.23
8.2.110.0080.00020.35
8.2.100.0090.00318.22
8.2.90.0030.00619.23
8.2.80.0030.00617.97
8.2.70.0080.00017.50
8.2.60.0040.00417.93
8.2.50.0080.00018.07
8.2.40.0060.00318.22
8.2.30.0040.00419.26
8.2.20.0060.00317.82
8.2.10.0000.00818.06
8.2.00.0030.00617.78
8.1.280.0070.00725.92
8.1.270.0030.00522.02
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0060.00323.88
8.1.230.0000.01219.15
8.1.220.0080.00017.74
8.1.210.0040.00418.77
8.1.200.0060.00317.35
8.1.190.0040.00417.35
8.1.180.0000.00818.10
8.1.170.0040.00718.40
8.1.160.0040.00421.98
8.1.150.0000.00818.90
8.1.140.0000.00717.46
8.1.130.0000.00717.89
8.1.120.0000.00717.35
8.1.110.0030.00517.32
8.1.100.0000.00717.48
8.1.90.0040.00417.39
8.1.80.0070.00317.46
8.1.70.0040.00417.45
8.1.60.0030.00517.61
8.1.50.0040.00417.42
8.1.40.0000.00817.43
8.1.30.0060.00317.61
8.1.20.0000.00717.60
8.1.10.0000.00717.54
8.1.00.0040.00817.46
8.0.300.0050.00318.77
8.0.290.0040.00416.75
8.0.280.0040.00418.52
8.0.270.0030.00317.22
8.0.260.0060.00017.18
8.0.250.0000.00716.85
8.0.240.0050.00216.98
8.0.230.0030.00316.95
8.0.220.0030.00316.89
8.0.210.0000.00716.79
8.0.200.0060.00316.84
8.0.190.0000.00716.91
8.0.180.0000.00816.90
8.0.170.0080.00016.82
8.0.160.0050.00216.86
8.0.150.0000.00716.70
8.0.140.0030.00616.75
8.0.130.0030.00313.29
8.0.120.0100.00016.75
8.0.110.0070.00016.74
8.0.100.0040.00416.94
8.0.90.0040.00416.76
8.0.80.0070.01416.83
8.0.70.0080.00016.97
8.0.60.0070.00016.85
8.0.50.0000.00716.89
8.0.30.0100.01417.08
8.0.20.0130.00617.40
8.0.10.0030.00517.07
8.0.00.0060.01516.60
7.4.330.0020.00215.14
7.4.320.0030.00316.61
7.4.300.0050.00216.53
7.4.290.0040.00416.51
7.4.280.0060.00016.53
7.4.270.0030.00316.52
7.4.260.0030.00616.64
7.4.250.0040.00416.64
7.4.240.0040.00416.59
7.4.230.0000.00716.36
7.4.220.0160.00616.43
7.4.210.0000.01416.56
7.4.200.0080.00016.71
7.4.160.0160.00016.34
7.4.150.0090.00917.40
7.4.140.0080.00917.86
7.4.130.0070.01516.51
7.4.120.0090.00916.43
7.4.110.0000.01616.32
7.4.100.0150.00616.55
7.4.90.0100.00716.60
7.4.80.0000.01619.37
7.4.70.0030.01416.64
7.4.60.0060.01216.36
7.4.50.0030.00616.44
7.4.40.0030.01316.56
7.4.30.0080.00816.45
7.4.00.0090.00614.89
7.3.330.0020.00213.34
7.3.320.0020.00213.20
7.3.310.0000.00716.45
7.3.300.0000.00716.30
7.3.290.0070.00716.45
7.3.280.0050.00916.31
7.3.270.0170.00017.40
7.3.260.0060.01216.48
7.3.250.0080.01216.55
7.3.240.0120.00616.63
7.3.230.0030.01316.64
7.3.210.0130.00316.47
7.3.200.0130.01019.39
7.3.190.0120.00616.49
7.3.180.0150.00616.73
7.3.170.0090.00616.59
7.3.160.0170.00316.40
7.2.330.0130.00316.60
7.2.320.0090.00916.43
7.2.310.0080.01116.64
7.2.300.0060.01316.63
7.2.290.0140.00616.47
7.2.00.0040.00819.68
7.1.100.0090.00317.88
7.1.70.0080.00317.04
7.1.60.0140.01019.32
7.1.50.0130.01016.93
7.1.00.0030.07722.43
7.0.200.0030.00616.74
7.0.140.0000.07722.23
7.0.60.0070.08020.02
7.0.50.0230.03017.86
7.0.40.0130.07320.24
7.0.30.0170.04020.10
7.0.20.0300.05020.09
7.0.10.0200.08020.11
7.0.00.0100.04720.25
5.6.280.0000.07720.91
5.6.210.0100.05720.53
5.6.200.0130.07018.15
5.6.190.0200.07320.50
5.6.180.0500.06720.61
5.6.170.0330.04020.56
5.6.160.0130.03320.44
5.6.150.0030.04018.15
5.6.140.0030.04018.17
5.6.130.0070.07018.14
5.6.120.0030.08020.90
5.6.110.0030.07021.04
5.6.100.0070.07021.04
5.6.90.0400.04021.11
5.6.80.0030.08720.53
5.5.350.0300.04320.35
5.5.340.0070.03718.05
5.5.330.0070.08320.25
5.5.320.0370.05020.28
5.5.310.0100.04720.36
5.5.300.0100.08017.94
5.5.290.0100.08018.02
5.5.280.0070.06020.67
5.5.270.0000.05020.73
5.5.260.0170.08020.87
5.5.250.0100.09020.77
5.5.240.2130.03320.26
5.4.450.3870.03719.55
5.4.440.0100.04019.39
5.4.430.1870.06319.52
5.4.420.4830.03719.43
5.4.410.3830.03719.15
5.4.400.3900.03719.13
5.4.390.4230.04019.17
5.4.380.3970.04018.98
5.4.370.4030.04019.13
5.4.360.3930.03718.94
5.4.350.0500.03719.14
5.4.340.0000.04019.23
5.4.320.4130.04019.04
5.4.310.4200.04319.15
5.4.300.3800.04019.17
5.4.290.4000.03718.93
5.4.280.3870.03719.04
5.4.270.4130.03719.15
5.4.260.4030.03319.06
5.4.250.1670.04319.25
5.4.240.0070.05019.09
5.4.230.4830.04019.16
5.4.220.3630.03319.05
5.4.210.3830.03319.20
5.4.200.3800.04019.17
5.4.190.3800.03319.16
5.4.180.3930.04018.98
5.4.170.4130.04319.21
5.4.160.4400.04019.18
5.4.150.3970.03319.09
5.4.140.3870.03316.50
5.4.130.3830.03316.25
5.4.120.4170.03016.48
5.4.110.3970.04016.53
5.4.100.4270.03716.33
5.4.90.4470.04316.48
5.4.80.4130.03316.44
5.4.70.4000.03016.55
5.4.60.3830.03716.43
5.4.50.1900.03016.50
5.4.40.2870.04016.54
5.4.30.3430.04016.62
5.4.20.3330.02716.50
5.4.10.4370.03716.34
5.4.00.3500.02715.89
5.3.290.4200.04014.70
5.3.280.3900.03714.59
5.3.270.4270.03314.64
5.3.260.4530.04314.64
5.3.250.4100.04014.61
5.3.240.3800.04014.65
5.3.230.3970.04014.65
5.3.220.3600.03714.57
5.3.210.3970.03314.46
5.3.200.4200.03714.57
5.3.190.4130.04014.57
5.3.180.3730.03714.71
5.3.170.4430.03014.60
5.3.160.1500.04014.72
5.3.150.2330.02714.59
5.3.140.1600.03314.45
5.3.130.3470.03314.55
5.3.120.2200.04014.71
5.3.110.3300.03314.58
5.3.100.3200.03314.05
5.3.90.3200.04014.11
5.3.80.3000.03714.02
5.3.70.2330.03314.05
5.3.60.2200.03313.96
5.3.50.2400.04013.98
5.3.40.4170.03014.00
5.3.30.3900.04013.98
5.3.20.3030.04013.69
5.3.10.3870.03713.81
5.3.00.3900.04313.79
5.2.170.3000.02311.30
5.2.160.2670.03011.11
5.2.150.3430.03011.04
5.2.140.2230.02711.20
5.2.130.2930.02011.25
5.2.120.3370.02311.16
5.2.110.3770.01711.06
5.2.100.3030.02711.16
5.2.90.3530.02711.05
5.2.80.3200.02711.16
5.2.70.3270.03311.10
5.2.60.3530.03010.99
5.2.50.3470.03011.07
5.2.40.3030.03011.05
5.2.30.2730.02711.05
5.2.20.2900.03011.01
5.2.10.2770.03310.91
5.2.00.2570.02310.75
5.1.60.2400.0279.99
5.1.50.2530.02710.14
5.1.40.2300.0279.89
5.1.30.2970.03310.30
5.1.20.2600.02310.41
5.1.10.2630.03710.12
5.1.00.2670.02010.22
5.0.50.1670.0208.56
5.0.40.1370.0208.31
5.0.30.1300.0338.21
5.0.20.1770.0208.16
5.0.10.1330.0208.07
5.0.00.1370.0308.15
4.4.90.1330.0105.84
4.4.80.1470.0235.84
4.4.70.1300.0135.76
4.4.60.1530.0205.86
4.4.50.1570.0235.77
4.4.40.1530.0275.89
4.4.30.1270.0175.87
4.4.20.1500.0205.91
4.4.10.1370.0175.90
4.4.00.1370.0235.92
4.3.110.1370.0135.71
4.3.100.1400.0105.81
4.3.90.1030.0105.67
4.3.80.0870.0535.79
4.3.70.1470.0175.73
4.3.60.1430.0075.71
4.3.50.1430.0135.83
4.3.40.1330.0235.75
4.3.30.0900.0234.87
4.3.20.0700.0134.88
4.3.10.0930.0204.88
4.3.00.0870.0204.88

preferences:
40.59 ms | 401 KiB | 5 Q