3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = [ 'fruits' => [ 'apple' => 'red', 'banana' => 'yellow' ], 'numbers' => [1, 2] ]; $array2 = [ 'fruits' => [ 'orange' => 'orange', 'apple' => 'green' // Should overwrite 'red' ], ]; $array3 = [ 'numbers' => [2, 3, 4], // Should extend, not replace 'colors' => ['blue', 'purple'] // New key should be added ]; function mergeNestedArraysInefficient(array $array, array ...$otherArrays) { foreach ($otherArrays as $other) { if (array_is_list($other)) { $array = array_values(array_unique(array_merge($array, $other))); continue; } foreach ($other as $k => $v) { if (is_array($v) && key_exists($k, $array)) { $array[$k] = mergeNestedArraysInefficient($array[$k], $v); } else { $array[$k] = $v; } } } return $array; } var_export(mergeNestedArraysInefficient($array1, $array2, $array3));

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.4.140.0150.00617.61
8.4.130.0130.00917.65
8.4.120.0130.00820.79
8.4.110.0040.00524.00
8.4.100.0120.00917.57
8.4.90.0110.01020.84
8.4.80.0090.01122.51
8.4.70.0130.00719.07
8.4.60.0100.01020.82
8.4.50.0150.00718.89
8.4.40.0070.01317.64
8.4.30.0070.01420.52
8.4.20.0110.01119.42
8.4.10.0090.00019.43
8.3.270.0220.01216.34
8.3.260.0120.00816.78
8.3.250.0030.00518.79
8.3.240.0150.00516.72
8.3.230.0100.00616.66
8.3.220.0100.00919.01
8.3.210.0080.00316.59
8.3.200.0060.01216.61
8.3.190.0100.00917.25
8.3.180.0090.00919.17
8.3.170.0090.00920.66
8.3.160.0090.00617.26
8.3.150.0090.00917.08
8.3.140.0080.00318.49
8.3.130.0080.00018.49
8.3.120.0130.00319.23
8.3.110.0030.01316.76
8.3.100.0060.00624.06
8.3.90.0110.00426.77
8.3.80.0050.00518.18
8.3.70.0120.00316.50
8.3.60.0040.01118.60
8.3.50.0100.00718.41
8.3.40.0130.00318.84
8.3.30.0150.00319.05
8.3.20.0070.01121.90
8.3.10.0120.00321.85
8.3.00.0120.00419.09
8.2.290.0100.00916.63
8.2.280.0100.01119.85
8.2.270.0090.00917.49
8.2.260.0000.00817.49
8.2.250.0030.00618.41
8.2.240.0100.00017.16
8.2.230.0130.00720.94
8.2.220.0090.01237.54
8.2.210.0040.00426.77
8.2.200.0040.00418.54
8.2.190.0040.01116.75
8.2.180.0110.00718.41
8.2.170.0130.00318.79
8.2.160.0150.00020.14
8.2.150.0060.01019.13
8.2.140.0110.00420.52
8.2.130.0070.00720.47
8.2.120.0070.00719.11
8.2.110.0070.00719.30
8.2.100.0150.00019.14
8.2.90.0040.01218.80
8.2.80.0110.00419.09
8.2.70.0000.01518.89
8.2.60.0150.00018.94
8.2.50.0060.00919.13
8.2.40.0130.00318.91
8.2.30.0060.01018.79
8.2.20.0090.00618.52
8.2.10.0060.01018.73
8.2.00.0160.00018.83
8.1.330.0050.00416.32
8.1.320.0130.00716.32
8.1.310.0040.01118.44
8.1.300.0160.00019.46
8.1.290.0080.00030.84
8.1.280.0150.00025.92
8.1.270.0130.00322.24
8.1.260.0130.00321.95
8.1.250.0140.00022.02
8.1.240.0150.00018.60
8.1.230.0080.00818.80
8.1.220.0060.00918.82
8.1.210.0110.00418.55
8.1.200.0150.00018.71
8.1.190.0110.00418.76
8.1.180.0040.01118.31
8.1.170.0120.00318.69
8.1.160.0120.00418.53
8.1.150.0120.00318.62
8.1.140.0070.00718.71
8.1.130.0040.01118.91
8.1.120.0130.00318.38
8.1.110.0080.00818.45
8.1.100.0060.00919.74
8.1.90.0100.00718.28
8.1.80.0070.01119.80
8.1.70.0120.00318.80
8.1.60.0040.01118.66
8.1.50.0070.00718.68
8.1.40.0100.00718.76
8.1.30.0060.01218.90
8.1.20.0200.00019.83
8.1.10.0100.01018.80
8.1.00.0080.00818.49

preferences:
31.58 ms | 403 KiB | 5 Q