3v4l.org

run code in 300+ PHP versions simultaneously
<?php function append(array $init, array $add, $key = null, $initialKeyExist = true) { $_init = $init; if (is_null($key)) { foreach ($add as $key => $value) $_init[$key] = $value; return array_merge($_init, $init); } else { if ($initialKeyExist) { $_init[$key] = $add; return [ $key => array_merge($_init[$key], $init[$key]) ]; } else { $init[$key] = array(); $_init[$key] = $add; return [ $key => array_merge($_init, $init) ]; } } } $a = [ 'phone' => [ 'code' => '+38', ], ]; $b = [ 'prefix' => '095', 'number' => '7700418', ]; var_dump(append($a, $b, 'phone')); $a = [ 'code' => '+38', ]; $b = [ 'prefix' => '095', 'number' => '7700418', ]; var_dump(append($a, $b)); $a = [ 'phone' => [ 'code' => '+38', ], ]; $b = [ 'prefix' => '095', 'number' => '7700418', ]; var_dump(append($a, $b, 'full'));
Output for git.master, git.master_jit, rfc.property-hooks
array(1) { ["phone"]=> array(3) { ["prefix"]=> string(3) "095" ["number"]=> string(7) "7700418" ["code"]=> string(3) "+38" } } array(3) { ["code"]=> string(3) "+38" ["prefix"]=> string(3) "095" ["number"]=> string(7) "7700418" } Warning: Undefined array key "full" in /in/7Kt44 on line 13 Fatal error: Uncaught TypeError: array_merge(): Argument #2 must be of type array, null given in /in/7Kt44:13 Stack trace: #0 /in/7Kt44(13): array_merge(Array, NULL) #1 /in/7Kt44(56): append(Array, Array, 'full') #2 {main} thrown in /in/7Kt44 on line 13
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:
44.36 ms | 402 KiB | 8 Q