Last active
March 8, 2024 07:45
-
-
Save tulik/30550e91c641c9a7564a407b691983ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function array_diff_assoc_recursive($array1, $array2) | |
{ | |
$difference = array(); | |
foreach ($array1 as $key => $value) { | |
if (is_array($value)) { | |
if (!isset($array2[$key]) || !is_array($array2[$key])) { | |
$difference[$key] = $value; | |
} else { | |
$new_diff = array_diff_assoc_recursive($value, $array2[$key]); | |
if (!empty($new_diff)) { | |
$difference[$key] = $new_diff; | |
} | |
} | |
} elseif (!array_key_exists($key, $array2) || $array2[$key] !== $value) { | |
$difference[$key] = $value; | |
} | |
} | |
return $difference; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment