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); $array1 = array("a" => "green", "red","b" => "brown",1,"d"=>array("a" => "green", "red","b" => "brown",1,"d"=>2)); $array2 = array("a" => "green","b" => "brown", "red",true,"d"=>array("a" => "green","b" => "brown", "red",true,"d"=>3)); $result = array_diff_assoc($array1, $array2); print_r($result); $resultRec = array_diff_assoc_recursive($array1,$array2); print_r($resultRec); ?>
based on eIFXS
Output for 5.4.0 - 7.2.0
Notice: Array to string conversion in /in/eqdBU on line 43 Notice: Array to string conversion in /in/eqdBU on line 43 Array ( ) Array ( [d] => Array ( [d] => 2 ) )
Output for 4.3.0 - 5.3.29
Array ( ) Array ( [d] => Array ( [d] => 2 ) )