3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php abstract class wtf { function array_merge_recursive_distinct() { $arrays = func_get_args(); $base = array_shift($arrays); foreach ($arrays as $array) { reset($base); //important while (list($key, $value) = @each($array)) { if (is_array($value) && @is_array($base[$key])) { $base[$key] = self::array_merge_recursive_distinct($base[$key], $value); } else { $base[$key] = $value; } } } return $base; } } $a = array( "exists" => 1, "doesnotexist" => 1, "arraytest" => array( "exists" => 1, "doesnotexist" => 1 ) ); $b = array( "exists" => 2, "arraytest" => array( "exists" => 2, ) ); $c = wtf::array_merge_recursive_distinct($a, $b); print_r($c);
based on RlNEo
Output for 7.0.0 - 7.2.0
Deprecated: Non-static method wtf::array_merge_recursive_distinct() should not be called statically in /in/TWFdk on line 39 Deprecated: Non-static method wtf::array_merge_recursive_distinct() should not be called statically in /in/TWFdk on line 12 Array ( [exists] => 2 [doesnotexist] => 1 [arraytest] => Array ( [exists] => 2 [doesnotexist] => 1 ) )
Output for 5.3.19 - 5.6.28
Strict Standards: Non-static method wtf::array_merge_recursive_distinct() should not be called statically in /in/TWFdk on line 39 Strict Standards: Non-static method wtf::array_merge_recursive_distinct() should not be called statically in /in/TWFdk on line 12 Array ( [exists] => 2 [doesnotexist] => 1 [arraytest] => Array ( [exists] => 2 [doesnotexist] => 1 ) )