3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); /** * https://stackoverflow.com/a/68884808/367456 */ $arr1 = [ "databases" => [ 0 => [ "id" => 1, "name" => "DB1", "slug" => "db1", "url" => "https://www.db1.org", ], ], ]; $arr2 = [ "databases" => [ 0 => [ "id" => 5, "name" => "DB2", "slug" => "db2", "url" => "https://www.db2.com", ], ], ]; /** * recursively go over two (optional) arrays old and new * while merging them. * * array values are then taken as: * * ['old' => $old, 'new' => $new]. * * @param array|null $old * @param array|null $new * @return array */ function old_and_new(array $old = null, array $new = null): array { $pair = get_defined_vars(); $map = static fn(callable $map, array $arrays): array => in_array(true, array_map('is_array', $arrays), true) && ($parameter = array_combine($k = array_keys($arrays), $k)) && ($keys = array_keys(array_flip(array_merge(...array_values(array_map('array_keys', array_filter($arrays, 'is_array')))))) ) ? array_map( static fn($key) => $map($map, array_map(static fn($p) => $arrays[$p][$key] ?? null, $parameter)), array_combine($keys, $keys) ) : $arrays; return $map($map, $pair); } print_r(old_and_new(new: $arr2));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [databases] => Array ( [0] => Array ( [id] => Array ( [old] => [new] => 5 ) [name] => Array ( [old] => [new] => DB2 ) [slug] => Array ( [old] => [new] => db2 ) [url] => Array ( [old] => [new] => https://www.db2.com ) ) ) )

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:
134.06 ms | 407 KiB | 5 Q