3v4l.org

run code in 300+ PHP versions simultaneously
<?php function arrayMergeRecursive($arraySource, $arrayDestination) { $temp = array(); foreach ($arraySource as $key => $value) { if (is_array($value)) { $associatedDestination = array(); if (isset($arrayDestination[$key])) { $associatedDestination = $arrayDestination[$key]; } $temp[$key] = arrayMergeRecursive($value, $associatedDestination); continue; } if (isset($arrayDestination[$key])) { $temp[$key] = $arrayDestination[$key]; } else { $temp[$key] = $arraySource[$key]; } } return $temp; } $source = ["a" => 1, "b" => 2, "c" => ["x" => 1, "y" => 2]]; $x = ["c" => 1, "d" => 10, "a" => 5]; var_dump(arrayMergeRecursive($source, $x)); var_dump(array_replace_recursive($source, $x));
Output for git.master, git.master_jit, rfc.property-hooks
array(3) { ["a"]=> int(5) ["b"]=> int(2) ["c"]=> array(2) { ["x"]=> int(1) ["y"]=> int(2) } } array(4) { ["a"]=> int(5) ["b"]=> int(2) ["c"]=> int(1) ["d"]=> int(10) }

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:
48.13 ms | 401 KiB | 8 Q