3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface ModifierInterface { public function apply(array $data, string $key): array; } class ArrayHelper { public static function mergeReverse(...$args): array { return self::applyModifiers(self::performMergeReverse(...$args)); } public static function merge(...$args): array { return self::applyModifiers(self::performMerge(...$args)); } private static function performMergeReverse(...$args): array { $res = array_pop($args) ?: []; while (!empty($args)) { foreach (array_pop($args) as $k => $v) { if (is_int($k)) { if (array_key_exists($k, $res) && $res[$k] !== $v) { $res[] = $v; } else { $res[$k] = $v; } } elseif (is_array($v) && isset($res[$k]) && is_array($res[$k])) { $res[$k] = self::performMergeReverse($v, $res[$k]); } elseif (!isset($res[$k])) { $res[$k] = $v; } } } return $res; } private static function performMerge(...$args): array { $res = array_shift($args) ?: []; while (!empty($args)) { foreach (array_shift($args) as $k => $v) { if (is_int($k)) { if (array_key_exists($k, $res) && $res[$k] !== $v) { $res[] = $v; } else { $res[$k] = $v; } } elseif (is_array($v) && isset($res[$k]) && is_array($res[$k])) { $res[$k] = self::performMerge($res[$k], $v); } else { $res[$k] = $v; } } } return $res; } public static function applyModifiers(array $data): array { $modifiers = []; foreach ($data as $k => $v) { if ($v instanceof ModifierInterface) { $modifiers[$k] = $v; unset($data[$k]); } elseif (is_array($v)) { $data[$k] = self::applyModifiers($v); } } foreach ($modifiers as $key => $modifier) { $data = $modifier->apply($data, $key); } return $data; } } $package = [ 'ApplicationStartup::class' => [ ['WebAppInfoCollector::class', 'collect'], ], 'ApplicationShutdown::class' => [ ['WebAppInfoCollector::class', 'collect'], ], ]; $app = [ 'ApplicationStartup::class' => [ ['AppStartup::class', 'start'], ], 'ApplicationShutdown::class' => [ ['AppShutdown::class', 'shutdown'], ], ]; $result = ArrayHelper::merge($package, $app); var_export($result); echo "\n\n"; $resultPop = ArrayHelper::mergeReverse($package, $app); var_export($resultPop);

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.120.0110.00820.49
8.4.110.0120.00922.49
8.4.100.0090.01017.57
8.4.90.0050.00618.66
8.4.80.0140.00818.12
8.4.70.0020.00617.80
8.4.60.0050.00418.81
8.4.50.0110.00818.36
8.4.40.0150.00617.67
8.4.30.0080.00018.79
8.4.20.0100.01017.94
8.4.10.0030.01320.65
8.3.250.0120.01018.97
8.3.240.0120.00816.80
8.3.230.0100.00916.86
8.3.220.0120.00419.00
8.3.210.0140.00418.48
8.3.200.0040.00416.32
8.3.190.0050.00417.17
8.3.180.0120.00318.79
8.3.170.0130.00617.14
8.3.160.0110.00718.43
8.3.150.0040.01216.69
8.3.140.0090.00616.71
8.3.130.0060.00318.63
8.3.120.0060.00319.16
8.3.110.0130.00020.94
8.3.100.0070.00324.06
8.3.90.0050.00326.77
8.3.80.0060.00319.36
8.3.70.0130.00318.56
8.3.60.0100.00516.36
8.3.50.0120.00924.45
8.3.40.0210.00019.18
8.3.30.0160.00618.67
8.3.20.0040.00424.18
8.3.10.0030.00624.66
8.3.00.0030.00626.16
8.2.290.0100.01020.31
8.2.280.0130.00620.07
8.2.270.0080.00016.78
8.2.260.0080.01217.17
8.2.250.0050.00317.00
8.2.240.0130.00717.42
8.2.230.0040.00422.58
8.2.220.0030.00637.54
8.2.210.0040.00426.77
8.2.200.0030.00618.88
8.2.190.0070.00716.58
8.2.180.0120.00925.92
8.2.170.0090.00622.96
8.2.160.0170.00322.96
8.2.150.0080.00025.66
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0080.00026.35
8.2.110.0000.00919.38
8.2.100.0090.00319.64
8.2.90.0000.00817.63
8.2.80.0060.00618.93
8.2.70.0040.00417.63
8.2.60.0000.00817.50
8.2.50.0030.00518.05
8.2.40.0080.00020.07
8.2.30.0000.00818.03
8.2.20.0000.00718.20
8.2.10.0040.00419.41
8.2.00.0000.00719.33
8.1.330.0090.00921.70
8.1.320.0120.00718.09
8.1.310.0000.01418.63
8.1.300.0070.00316.26
8.1.290.0090.00030.84
8.1.280.0140.00325.92
8.1.270.0000.00823.99
8.1.260.0030.00628.09
8.1.250.0040.00428.09
8.1.240.0060.00319.06
8.1.230.0070.00419.13
8.1.220.0050.00317.74
8.1.210.0080.00018.77
8.1.200.0080.00017.63
8.1.190.0040.00417.35
8.1.180.0030.00618.10
8.1.170.0050.00218.87
8.1.160.0000.00818.92
8.1.150.0040.00418.84
8.1.140.0070.00018.82
8.1.130.0030.00320.17
8.1.120.0040.00417.37
8.1.110.0000.00717.46
8.1.100.0040.00417.36
8.1.90.0000.00817.50
8.1.80.0030.00517.53
8.1.70.0000.00717.38
8.1.60.0030.00617.57
8.1.50.0030.00617.60
8.1.40.0040.00417.47
8.1.30.0040.00417.64
8.1.20.0060.00317.68
8.1.10.0000.00817.60
8.1.00.0000.00817.42
8.0.300.0040.00418.77
8.0.290.0000.00816.63
8.0.280.0050.00318.44
8.0.270.0000.00718.03
8.0.260.0000.00720.24
8.0.250.0030.00517.00
8.0.240.0030.00316.94
8.0.230.0030.00317.02
8.0.220.0000.00716.91
8.0.210.0000.00816.96
8.0.200.0040.00416.95
8.0.190.0050.00316.85
8.0.180.0000.00816.93
8.0.170.0000.00916.95
8.0.160.0000.00816.97
8.0.150.0000.00816.79
8.0.140.0050.00216.77
8.0.130.0060.00013.44
8.0.120.0000.00716.88
8.0.110.0000.00816.86
8.0.100.0000.00816.95
8.0.90.0030.00616.94
8.0.80.0060.00916.81
8.0.70.0040.00416.87
8.0.60.0000.00716.79
8.0.50.0040.00416.81
8.0.30.0110.00617.07
8.0.20.0120.00817.30
8.0.10.0050.00316.88
8.0.00.0170.00416.98
7.4.330.0000.00515.55
7.4.320.0030.00316.46
7.4.300.0030.00616.48
7.4.290.0040.00416.54
7.4.280.0040.00416.54
7.4.270.0000.00716.55
7.4.260.0050.00013.30
7.4.250.0000.00816.39
7.4.240.0010.00616.55
7.4.230.0030.00316.52
7.4.220.0040.00416.56
7.4.210.0100.00916.61
7.4.200.0000.00816.58
7.4.130.0080.01316.48
7.4.120.0130.01316.61
7.4.110.0100.00716.60
7.4.100.0140.00416.50
7.4.90.0110.00716.68
7.4.80.0120.00619.39
7.4.70.0100.00716.74
7.4.60.0110.00616.53
7.4.50.0080.00816.49
7.4.40.0120.00616.53
7.4.30.0000.02016.46
7.4.20.0000.01716.58
7.4.10.0170.00016.56
7.4.00.0120.00416.56
7.3.330.0050.00316.38
7.3.320.0020.00213.31
7.3.310.0030.00316.41
7.3.300.0030.00516.24
7.3.290.0060.00816.36
7.3.260.0090.01016.51
7.3.240.0090.00916.57
7.3.230.0090.00916.46
7.3.210.0160.00316.28
7.3.200.0070.01016.45
7.3.190.0030.01316.39
7.3.180.0120.00416.43
7.3.170.0060.01016.33
7.3.160.0100.00616.27
7.3.150.0070.01316.62
7.3.140.0030.01216.37
7.3.130.0040.01116.52
7.3.120.0090.00616.33
7.3.110.0120.00416.37
7.3.100.0070.00816.67
7.3.90.0040.01216.35
7.3.80.0030.01216.52
7.3.70.0080.00816.49
7.3.60.0100.00616.37
7.3.50.0080.00816.47
7.3.40.0140.00016.43
7.3.30.0060.00916.42
7.3.20.0150.00316.41
7.3.10.0190.00016.41
7.3.00.0030.01416.40
7.2.330.0140.00616.69
7.2.320.0130.00816.51
7.2.310.0100.00716.61
7.2.300.0060.01016.71
7.2.290.0120.00916.47
7.2.280.0000.02016.86
7.2.270.0130.00716.57
7.2.260.0130.00316.82
7.2.250.0100.00616.82
7.2.240.0100.00616.76
7.2.230.0030.01316.61
7.2.220.0000.01716.91
7.2.210.0090.00816.81
7.2.200.0070.01016.52
7.2.190.0060.01116.88
7.2.180.0060.00916.49
7.2.170.0120.00316.79
7.2.160.0060.00916.82
7.2.150.0030.01416.68
7.2.140.0090.00916.80
7.2.130.0100.00716.86
7.2.120.0060.01516.81
7.2.110.0240.01416.69
7.2.100.0060.01216.70
7.2.90.0100.00716.63
7.2.80.0030.01416.82
7.2.70.0040.01216.64
7.2.60.0100.00716.52
7.2.50.0120.00316.66
7.2.40.0030.01216.62
7.2.30.0110.00516.90
7.2.20.0130.00316.63
7.2.10.0100.00716.63
7.2.00.0070.01016.75

preferences:
27.68 ms | 403 KiB | 5 Q