3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Non-static method wtf::array_merge_recursive_distinct() cannot be called statically in /in/TWFdk:39 Stack trace: #0 {main} thrown in /in/TWFdk on line 39
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
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 7.3.32 - 7.3.33
Array ( [exists] => 2 [doesnotexist] => 1 [arraytest] => Array ( [exists] => 2 [doesnotexist] => 1 ) )
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 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 ) )

preferences:
189.35 ms | 403 KiB | 272 Q