3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mergeAttachments($a, $b) { // If both #attached arrays contain drupalSettings, then merge them // correctly; adding the same settings multiple times needs to behave // idempotently. if (!empty($a['drupalSettings']) && !empty($b['drupalSettings'])) { $drupalSettings = mergeDeepArray(array($a['drupalSettings'], $b['drupalSettings']), TRUE); // No need for re-merging them. unset($a['drupalSettings']); unset($b['drupalSettings']); } // Apply the normal merge. $a = mergeDeepArray(array($a, $b)); if (isset($drupalSettings)) { // Save the custom merge for the drupalSettings. $a['drupalSettings'] = $drupalSettings; } return $a; } function mergeAttachmentsOld($a, $b) { if (!empty($a['drupalSettings']) && !empty($b['drupalSettings'])) { $a['drupalSettings'] = mergeDeepArray([$a['drupalSettings'], $b['drupalSettings']], TRUE); unset($b['drupalSettings']); } return mergeDeep($a, $b); } function mergeDeepArray($arrays, $preserve_integer_keys = FALSE) { $result = array(); foreach ($arrays as $array) { foreach ($array as $key => $value) { // Renumber integer keys as array_merge_recursive() does unless // $preserve_integer_keys is set to TRUE. Note that PHP automatically // converts array keys that are integer strings (e.g., '1') to integers. if (is_integer($key) && !$preserve_integer_keys) { $result[] = $value; } // Recurse when both values are arrays. elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) { $result[$key] = mergeDeepArray(array($result[$key], $value), $preserve_integer_keys); } // Otherwise, use the latter value, overriding any previous value. else { $result[$key] = $value; } } } return $result; } function mergeDeep() { return mergeDeepArray(func_get_args()); } for($i = 0; $i <= 100000; $i++) { $a['#attached'] = array( 'library' => array( 'core/drupal', 'core/drupalSettings', ), ); $b['#attached'] = array( 'library' => array( 'core/jquery', ), ); mergeAttachments($a['#attached'], $b['#attached']); $a['#attached'] = array( 'js' => array( 'foo.js' => array(), 'bar.js' => array(), ), 'drupalSettings' => [ 'foo' => ['d'], ], ); $b['#attached'] = array( 'js' => array( 'baz.js' => array(), ), 'drupalSettings' => [ 'bar' => ['a', 'b', 'c'], ], ); mergeAttachments($a['#attached'], $b['#attached']); }

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.70.0070.21516.48
8.3.60.0130.25416.63
8.3.50.0100.21422.05
8.3.40.0030.19718.84
8.3.30.0070.19919.18
8.3.20.0070.10020.27
8.3.10.0030.10621.73
8.3.00.0100.10320.75
8.2.190.0030.20416.63
8.2.180.0100.21316.88
8.2.170.0030.19822.96
8.2.160.0070.20022.11
8.2.150.0000.10924.18
8.2.140.0100.11224.66
8.2.130.0070.10526.16
8.2.120.0100.11919.95
8.2.110.0000.22820.94
8.2.100.0100.18217.97
8.2.90.0030.19617.91
8.2.80.0030.18417.97
8.2.70.0030.18517.63
8.2.60.0070.17918.03
8.2.50.0030.17918.07
8.2.40.0030.18118.28
8.2.30.0070.20218.03
8.2.20.0030.18117.69
8.2.10.0070.18318.19
8.2.00.0070.18417.73
8.1.280.0100.20825.92
8.1.270.0070.10620.78
8.1.260.0070.11826.35
8.1.250.0070.10228.09
8.1.240.0030.21922.05
8.1.230.0100.15920.95
8.1.220.0030.18217.74
8.1.210.0070.17018.77
8.1.200.0030.19617.35
8.1.190.0030.18917.12
8.1.180.0070.18118.10
8.1.170.0000.17518.71
8.1.160.0070.17022.04
8.1.150.0070.18018.99
8.1.140.0030.18519.09
8.1.130.0030.17817.76
8.1.120.0030.18817.43
8.1.110.0030.18717.41
8.1.100.0030.18717.53
8.1.90.0100.18217.45
8.1.80.0000.18617.50
8.1.70.0070.18517.49
8.1.60.0000.21817.64
8.1.50.0030.21417.44
8.1.40.0030.21217.50
8.1.30.0030.21517.68
8.1.20.0070.20617.65
8.1.10.0030.21017.52
8.1.00.0030.23617.45
8.0.300.0030.17420.03
8.0.290.0070.18816.63
8.0.280.0030.19218.48
8.0.270.0030.20716.88
8.0.260.0100.21217.29
8.0.250.0100.18516.99
8.0.240.0000.19716.94
8.0.230.0000.19816.87
8.0.220.0030.20016.88
8.0.210.0000.19516.95
8.0.200.0000.19717.02
8.0.190.0070.21216.97
8.0.180.0000.21716.98
8.0.170.0030.21416.94
8.0.160.0030.21316.97
8.0.150.0100.21016.85
8.0.140.0030.21516.87
8.0.130.0100.20913.36
8.0.120.0000.21816.79
8.0.110.0070.21116.95
8.0.100.0030.21416.91
8.0.90.0030.21816.99
8.0.80.0130.36216.96
8.0.70.0030.22016.81
8.0.60.0030.21716.89
8.0.50.0030.21616.77
8.0.30.0160.43917.31
8.0.20.0100.30217.40
8.0.10.0070.21116.98
8.0.00.0140.46016.91
7.4.330.0000.19615.03
7.4.320.0070.19216.63
7.4.300.0030.19816.54
7.4.290.0030.21616.57
7.4.280.0000.21816.52
7.4.270.0000.22216.64
7.4.260.0000.22016.49
7.4.250.0030.21716.52
7.4.240.0050.21916.63
7.4.230.0030.21716.70
7.4.220.0100.36116.54
7.4.210.0030.33116.71
7.4.200.0030.21716.48
7.4.160.0030.35516.58
7.4.150.0030.32317.40
7.4.140.0130.35117.86
7.4.130.0100.31716.69
7.4.120.0160.30316.52
7.4.110.0100.30116.79
7.4.100.0070.34316.57
7.4.90.0170.38816.46
7.4.80.0090.36316.45
7.4.70.0070.32516.68
7.4.60.0100.30616.59
7.4.50.0030.18316.36
7.4.40.0100.31716.44
7.4.30.0070.31616.55
7.4.00.0070.35814.93
7.3.330.0000.22613.25
7.3.320.0100.22113.34
7.3.310.0030.22116.49
7.3.300.0030.22016.41
7.3.290.0070.39416.39
7.3.280.0110.37816.36
7.3.270.0100.29317.40
7.3.260.0160.45516.55
7.3.250.0110.30116.48
7.3.240.0100.32816.66
7.3.230.0130.29316.67
7.3.210.0060.32916.45
7.3.200.0120.34419.39
7.3.190.0160.45716.38
7.3.180.0100.51216.52
7.3.170.0030.32016.63
7.3.160.0130.35916.44
7.3.120.0070.37414.62
7.3.110.0100.42914.84
7.3.100.0070.37214.92
7.3.90.0070.36214.84
7.3.80.0070.45714.89
7.3.70.0100.47314.91
7.3.60.0070.42115.00
7.3.50.0070.38914.64
7.3.40.0070.44214.86
7.3.30.0030.47214.83
7.3.20.0030.38116.41
7.3.10.0100.33316.71
7.3.00.0070.36916.52
7.2.330.0100.35916.54
7.2.320.0030.35416.76
7.2.310.0410.65116.62
7.2.300.0130.37216.85
7.2.290.0030.40316.48
7.2.250.0100.41915.30
7.2.240.0100.53014.95
7.2.230.0070.49315.00
7.2.220.0100.52014.87
7.2.210.0100.40315.13
7.2.200.0030.52115.16
7.2.190.0000.52714.91
7.2.180.0070.44115.35
7.2.170.0000.49115.23
7.2.60.0000.23216.95
7.2.50.0130.19916.97
7.1.330.0030.58715.65
7.1.320.0030.60915.96
7.1.310.0070.56515.54
7.1.300.0030.60815.89
7.1.290.0070.50015.46
7.1.280.0070.60315.84
7.1.270.0070.58715.68
7.1.260.0070.49615.89
7.1.200.0030.20915.80
7.1.70.0030.22517.13
7.1.60.0070.28019.46
7.1.50.0030.21716.76
7.1.00.0030.39722.46
7.0.200.0070.23314.89
7.0.140.0000.36722.00
7.0.100.0100.31019.97
7.0.90.0130.33020.20
7.0.80.0330.32719.89
7.0.70.0200.33019.89
7.0.60.0030.33320.09
7.0.50.0300.31320.37
7.0.40.0000.27320.11
7.0.30.0070.36320.00
7.0.20.0070.25720.07
7.0.10.0170.34320.05
7.0.00.0130.34320.08
5.6.280.0071.00721.13
5.6.250.0070.89720.64
5.6.240.0030.96320.69
5.6.230.0030.90020.57
5.6.220.0070.82720.69
5.6.210.0030.90320.58
5.6.200.0030.92320.97
5.6.190.0170.93021.05
5.6.180.0100.93721.07
5.6.170.0100.92021.09
5.6.160.0171.08021.05
5.6.150.0030.82321.15
5.6.140.0000.93721.06
5.6.130.0030.82720.97
5.6.120.0030.79321.12
5.6.110.0000.94020.95
5.6.100.0200.92321.02
5.6.90.0100.89721.04
5.6.80.0100.92720.36
5.6.70.0200.91020.41
5.6.60.0000.88720.42
5.6.50.0100.95320.57
5.6.40.0130.93020.32
5.6.30.0070.94320.33
5.6.20.0130.92720.48
5.6.10.0070.91720.50
5.6.00.0100.83020.41
5.5.380.1100.96320.33
5.5.370.0071.05320.38
5.5.360.0070.95720.55
5.5.350.0131.00020.39
5.5.340.0030.99320.89
5.5.330.0131.03720.95
5.5.320.0171.01720.94
5.5.310.0100.97020.88
5.5.300.0030.87020.77
5.5.290.0070.80320.80
5.5.280.0030.86020.77
5.5.270.0031.07320.84
5.5.260.0100.99720.89
5.5.250.0071.02020.66
5.5.240.0100.97720.28
5.5.230.0131.02320.27
5.5.220.0071.03720.25
5.5.210.0071.01720.28
5.5.200.0001.02320.22
5.5.190.0071.04020.14
5.5.180.0100.89320.14
5.5.160.0130.98720.25
5.5.150.0031.01720.14
5.5.140.0100.89020.16
5.5.130.0001.05320.29
5.5.120.0130.99720.09
5.5.110.0071.02320.12
5.5.100.0131.00320.09
5.5.90.0100.98320.17
5.5.80.0001.00320.07
5.5.70.0170.98020.16
5.5.60.0070.87720.12
5.5.50.0030.99720.07
5.5.40.0070.87020.15
5.5.30.0100.92020.15
5.5.20.0071.00320.07
5.5.10.0070.82020.06
5.5.00.0030.99020.07
5.4.450.0070.84719.38
5.4.440.0070.95019.38
5.4.430.0030.96719.51
5.4.420.0170.89719.36
5.4.410.0130.98019.15
5.4.400.0070.98319.04
5.4.390.0100.84719.03
5.4.380.0100.96319.03
5.4.370.0130.82018.96
5.4.360.0000.98019.18
5.4.350.0030.96719.24
5.4.340.0070.87719.13
5.4.320.0070.94719.21
5.4.310.0130.96719.04
5.4.300.0100.98318.88
5.4.290.0070.87718.97
5.4.280.0000.91719.13
5.4.270.0030.99718.95
5.4.260.0070.97318.87
5.4.250.0070.95719.03
5.4.240.0131.00319.23
5.4.230.0070.93719.15
5.4.220.0100.96319.15
5.4.210.0030.84719.20
5.4.200.0030.98019.23
5.4.190.0070.99719.16
5.4.180.0071.00319.22
5.4.170.0100.89319.02
5.4.160.0000.98019.01
5.4.150.0030.94019.02
5.4.140.0171.03016.42
5.4.130.0030.99716.40
5.4.120.0100.98016.40
5.4.110.0070.99316.47
5.4.100.0071.01716.38
5.4.90.0071.00716.41
5.4.80.0131.00316.47
5.4.70.0130.99316.51
5.4.60.0100.97316.43
5.4.50.0030.98716.49
5.4.40.0030.98316.54
5.4.30.0000.97716.33
5.4.20.0070.98716.33
5.4.10.0070.95716.48
5.4.00.0070.98315.58
5.3.290.0030.07314.60
5.3.280.0000.04014.59
5.3.270.0130.06714.75
5.3.260.0130.04014.63
5.3.250.0030.07714.63
5.3.240.0000.08014.63
5.3.230.0070.07714.74
5.3.220.0100.07314.55
5.3.210.0030.08314.55
5.3.200.0070.07314.66
5.3.190.0130.07014.51
5.3.180.0030.07314.68
5.3.170.0100.07314.59
5.3.160.0070.07314.52
5.3.150.0030.04714.52
5.3.140.0070.05314.62
5.3.130.0030.08314.54
5.3.120.0070.07714.53
5.3.110.0030.08014.53
5.3.100.0000.04014.16
5.3.90.0070.07314.09
5.3.80.0070.07714.01
5.3.70.0100.07714.09
5.3.60.0070.06314.07
5.3.50.0070.07314.01
5.3.40.0030.07714.04
5.3.30.0070.07013.92
5.3.20.0130.06713.73
5.3.10.0030.07313.71
5.3.00.0100.06013.79
5.2.170.0030.05711.17
5.2.160.0070.06011.17
5.2.150.0030.06011.17
5.2.140.0100.05711.17
5.2.130.0070.06011.17
5.2.120.0070.03711.17
5.2.110.0030.03311.17
5.2.100.0030.03311.17
5.2.90.0030.03711.17
5.2.80.0030.06711.22
5.2.70.0070.06311.17
5.2.60.0070.05711.17
5.2.50.0000.07011.17
5.2.40.0100.04711.17
5.2.30.0030.06311.17
5.2.20.0000.06311.17
5.2.10.0000.06011.17
5.2.00.0100.03311.17
5.1.60.0070.05011.17
5.1.50.0100.04311.17
5.1.40.0030.05711.17
5.1.30.0070.05711.17
5.1.20.0070.05311.17
5.1.10.0100.05011.17
5.1.00.0070.05011.17
5.0.50.0070.04311.17
5.0.40.0000.04311.17
5.0.30.0030.06711.17
5.0.20.0030.04311.17
5.0.10.0070.04011.17
5.0.00.0000.04711.17
4.4.90.0000.02311.17
4.4.80.0030.03311.17
4.4.70.0030.03311.17
4.4.60.0030.03011.17
4.4.50.0130.02711.17
4.4.40.0000.05311.17
4.4.30.0000.04011.17
4.4.20.0070.03011.17
4.4.10.0070.03011.17
4.4.00.0000.06011.17
4.3.110.0030.03011.17
4.3.100.0000.03711.17
4.3.90.0000.03711.17
4.3.80.0070.05011.17
4.3.70.0000.03311.17
4.3.60.0000.04011.17
4.3.50.0000.03711.17
4.3.40.0100.03711.17
4.3.30.0000.02711.17
4.3.20.0030.03311.17
4.3.10.0000.03711.17
4.3.00.0000.03311.17

preferences:
50.09 ms | 401 KiB | 5 Q