3v4l.org

run code in 300+ PHP versions simultaneously
<?php function extend($base, $replacements) { $base = !is_array($base) ? array() : $base; $replacements = !is_array($replacements) ? array() : $replacements; $ret = array(); foreach ($base as $key => $val) { if (is_int($key)) { // value without key $ret[$val] = null; } else { $ret[$key] = $val; } } return array_replace_recursive($ret, $replacements); } var_dump(extend(array('foo' => 'bar'), array('bar' => 'baz'))); var_dump(extend(array('foo' => 'bar'), array('foo' => 'foo'))); var_dump(extend(array('bar' => 'baz'), array('bar' => 'bar'))); var_dump(extend(array('bar' => 'baz'))); var_dump(extend(array('bar' => 'baz')));
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { ["foo"]=> string(3) "bar" ["bar"]=> string(3) "baz" } array(1) { ["foo"]=> string(3) "foo" } array(1) { ["bar"]=> string(3) "bar" } Fatal error: Uncaught ArgumentCountError: Too few arguments to function extend(), 1 passed in /in/JHEUh on line 22 and exactly 2 expected in /in/JHEUh:3 Stack trace: #0 /in/JHEUh(22): extend(Array) #1 {main} thrown in /in/JHEUh on line 3
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
67.56 ms | 401 KiB | 8 Q