3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function array_diff_assoc_recursive($array1, $array2) { foreach($array1 as $key => $value) { if(is_array($value)) { if(!isset($array2[$key])) { $difference[$key] = $value; } elseif(!is_array($array2[$key])) { $difference[$key] = $value; } else { $new_diff = array_diff_assoc_recursive($value, $array2[$key]); if($new_diff != FALSE) { $difference[$key] = $new_diff; } } } elseif(!array_key_exists($key, $array2) || $array2[$key] != $value) { $difference[$key] = $value; } } return !isset($difference) ? 0 : $difference; } $array1 = array("a" => "green", "red","b" => "brown",1,"d"=>1); $array2 = array("a" => "green","b" => "brown", "red",true,"d"=>true); $result = array_diff_assoc($array1, $array2); print_r($result); $array1 = array("a" => "green", "red","b" => "brown",1,"d"=>array("a" => "green", "red","b" => "brown",1,"d"=>1)); $array2 = array("a" => "green","b" => "brown", "red",true,"d"=>array("a" => "green","b" => "brown", "red",true,"d"=>true)); $resultRec = array_diff_assoc_recursive($array1,$array2); print_r($resultRec); ?>
based on e8qfR
Output for 4.3.0 - 7.2.0
Array ( ) 0