3v4l.org

run code in 300+ PHP versions simultaneously
<?php function arrayMergeRecursiveDistinct(array $first, array $second) { foreach ($second as $idx => $value) { if (is_integer($idx)) { $first[] = $value; } else { if (!array_key_exists($idx, $first)) { $first[$idx] = $value; } else { if (is_array($value)) { $first[$idx] = arrayMergeRecursiveDistinct($first[$idx], $value); } else { $first[$idx] = $value; } } } } return $first; } $a = ['a' => [1,2,3], 'b' => ['c' => ['d' => 'e']]]; $b = ['a' => [1,2,3,4], 'b']; print_r(arrayMergeRecursiveDistinct($b, $a)); print_r(array_replace_recursive($b, $a));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [a] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 1 [5] => 2 [6] => 3 ) [0] => b [b] => Array ( [c] => Array ( [d] => e ) ) ) Array ( [a] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) [0] => b [b] => Array ( [c] => Array ( [d] => e ) ) )

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:
64.78 ms | 402 KiB | 8 Q