3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input1 = ['hotels' => [ 'hotel' => [ [ "ort" => "rom", "lioc" => "inrom" ], [ "ort" => "paris", "lioc" => "inpsrisd" ], [ "ort" => "berlin", "lioc" => "inberlin" ], [ "ort" => "milano", "lioc" => "inmilano" ], [ "ort" => "paris", "lioc" => "anotherinpsrisd"], [ "ort" => "muc", "lioc" => "inmuc"] ] ]]; $input2 = ['hotels' => [ 'hotel' => [ [ "ort" => "rom", "lioc" => "inrom" ], [ "ort" => "beijing", "lioc" => "wanda" ] ] ]]; function recursiveUnique($input): array { // if the input is not an array, just return the input if (!is_array($input)) { return $input; } // check if the array is a list or an associative array else if (count($input) === 0 || array_keys($input) === range(0, count($input) - 1)) { return array_values(array_unique($input, SORT_REGULAR)); } else { foreach ($input as $key => $value) { $input[$key] = recursiveUnique($value); } return $input; } } var_dump(recursiveUnique(array_merge_recursive($input1, $input2)));
Output for git.master, git.master_jit, rfc.property-hooks
array(1) { ["hotels"]=> array(1) { ["hotel"]=> array(7) { [0]=> array(2) { ["ort"]=> string(3) "rom" ["lioc"]=> string(5) "inrom" } [1]=> array(2) { ["ort"]=> string(5) "paris" ["lioc"]=> string(8) "inpsrisd" } [2]=> array(2) { ["ort"]=> string(6) "berlin" ["lioc"]=> string(8) "inberlin" } [3]=> array(2) { ["ort"]=> string(6) "milano" ["lioc"]=> string(8) "inmilano" } [4]=> array(2) { ["ort"]=> string(5) "paris" ["lioc"]=> string(15) "anotherinpsrisd" } [5]=> array(2) { ["ort"]=> string(3) "muc" ["lioc"]=> string(5) "inmuc" } [6]=> array(2) { ["ort"]=> string(7) "beijing" ["lioc"]=> string(5) "wanda" } } } }

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:
27.68 ms | 408 KiB | 5 Q