3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $a1 = ['a', 'b']; $a2 = ['foo' => 'a', 'bar' => 'b']; $a3 = ['c', 'd']; $a4 = ['zip' => 'c', 'qux' => 'd']; $as = ['a1' => $a1, 'a2' => $a2, 'a3' => $a3, 'a4' => $a4]; foreach ($as as $kx => $ax) { foreach ($as as $ky => $ay) { printf('%s + %s : %s', $kx, $ky, print_r($ax + $ay, true)); echo PHP_EOL; printf('array_merge(%s, %s) : %s', $kx, $ky, print_r(array_merge($ax, $ay), true)); echo PHP_EOL; } }
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
a1 + a1 : Array ( [0] => a [1] => b ) array_merge(a1, a1) : Array ( [0] => a [1] => b [2] => a [3] => b ) a1 + a2 : Array ( [0] => a [1] => b [foo] => a [bar] => b ) array_merge(a1, a2) : Array ( [0] => a [1] => b [foo] => a [bar] => b ) a1 + a3 : Array ( [0] => a [1] => b ) array_merge(a1, a3) : Array ( [0] => a [1] => b [2] => c [3] => d ) a1 + a4 : Array ( [0] => a [1] => b [zip] => c [qux] => d ) array_merge(a1, a4) : Array ( [0] => a [1] => b [zip] => c [qux] => d ) a2 + a1 : Array ( [foo] => a [bar] => b [0] => a [1] => b ) array_merge(a2, a1) : Array ( [foo] => a [bar] => b [0] => a [1] => b ) a2 + a2 : Array ( [foo] => a [bar] => b ) array_merge(a2, a2) : Array ( [foo] => a [bar] => b ) a2 + a3 : Array ( [foo] => a [bar] => b [0] => c [1] => d ) array_merge(a2, a3) : Array ( [foo] => a [bar] => b [0] => c [1] => d ) a2 + a4 : Array ( [foo] => a [bar] => b [zip] => c [qux] => d ) array_merge(a2, a4) : Array ( [foo] => a [bar] => b [zip] => c [qux] => d ) a3 + a1 : Array ( [0] => c [1] => d ) array_merge(a3, a1) : Array ( [0] => c [1] => d [2] => a [3] => b ) a3 + a2 : Array ( [0] => c [1] => d [foo] => a [bar] => b ) array_merge(a3, a2) : Array ( [0] => c [1] => d [foo] => a [bar] => b ) a3 + a3 : Array ( [0] => c [1] => d ) array_merge(a3, a3) : Array ( [0] => c [1] => d [2] => c [3] => d ) a3 + a4 : Array ( [0] => c [1] => d [zip] => c [qux] => d ) array_merge(a3, a4) : Array ( [0] => c [1] => d [zip] => c [qux] => d ) a4 + a1 : Array ( [zip] => c [qux] => d [0] => a [1] => b ) array_merge(a4, a1) : Array ( [zip] => c [qux] => d [0] => a [1] => b ) a4 + a2 : Array ( [zip] => c [qux] => d [foo] => a [bar] => b ) array_merge(a4, a2) : Array ( [zip] => c [qux] => d [foo] => a [bar] => b ) a4 + a3 : Array ( [zip] => c [qux] => d [0] => c [1] => d ) array_merge(a4, a3) : Array ( [zip] => c [qux] => d [0] => c [1] => d ) a4 + a4 : Array ( [zip] => c [qux] => d ) array_merge(a4, a4) : Array ( [zip] => c [qux] => d )
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/LHl0q on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/LHl0q on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/LHl0q on line 3
Process exited with code 255.