3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_unpack(array $arg1, array $arg2) { return [...$arg1, ...$arg2]; } $arr1 = range(1, 100); $arr2 = array_combine(range('a', chr(ord('a') + 99)), range(1, 100)); $max = 10000; $start = microtime(true); for ($i = 0; $i < $max; $i++) { $res1 = array_merge($arr1, $arr2); } print("array_merge:\n"); printf("Took %.7f seconds per execution\n", (microtime(true) - $start) / $max); $max = 10000; $start = microtime(true); for ($i = 0; $i < $max; $i++) { $res2 = array_unpack($arr1, $arr2); } print("array_unpack:\n"); printf("Took %.7f seconds per execution\n", (microtime(true) - $start) / $max); assert($res1 === $res2);
Output for 8.1.2, 8.2.7
array_merge: Took 0.0000012 seconds per execution array_unpack: Took 0.0000019 seconds per execution
Output for 8.2.3
array_merge: Took 0.0000012 seconds per execution array_unpack: Took 0.0000020 seconds per execution
Output for 8.1.1, 8.1.4 - 8.1.5, 8.1.9 - 8.1.16
array_merge: Took 0.0000011 seconds per execution array_unpack: Took 0.0000019 seconds per execution
Output for 8.1.6 - 8.1.8
array_merge: Took 0.0000011 seconds per execution array_unpack: Took 0.0000018 seconds per execution
Output for 8.1.3
array_merge: Took 0.0000011 seconds per execution array_unpack: Took 0.0000021 seconds per execution
Output for 8.1.0
array_merge: Took 0.0000014 seconds per execution array_unpack: Took 0.0000022 seconds per execution
Output for 7.4.0 - 7.4.3, 7.4.5 - 7.4.18, 7.4.20 - 7.4.22, 7.4.24 - 7.4.26, 7.4.28 - 7.4.30, 8.0.1 - 8.0.22
array_merge: Took 0.0000011 seconds per execution Fatal error: Uncaught Error: Cannot unpack array with string keys in /in/v5m9f:5 Stack trace: #0 /in/v5m9f(22): array_unpack(Array, Array) #1 {main} thrown in /in/v5m9f on line 5
Process exited with code 255.
Output for 7.4.19, 7.4.23, 7.4.27
array_merge: Took 0.0000012 seconds per execution Fatal error: Uncaught Error: Cannot unpack array with string keys in /in/v5m9f:5 Stack trace: #0 /in/v5m9f(22): array_unpack(Array, Array) #1 {main} thrown in /in/v5m9f on line 5
Process exited with code 255.
Output for 7.4.4
array_merge: Took 0.0000013 seconds per execution Fatal error: Uncaught Error: Cannot unpack array with string keys in /in/v5m9f:5 Stack trace: #0 /in/v5m9f(22): array_unpack(Array, Array) #1 {main} thrown in /in/v5m9f on line 5
Process exited with code 255.

preferences:
102.78 ms | 401 KiB | 69 Q