Skip to content

Instantly share code, notes, and snippets.

@tulik
Last active March 8, 2024 07:45
Show Gist options
  • Save tulik/30550e91c641c9a7564a407b691983ad to your computer and use it in GitHub Desktop.
Save tulik/30550e91c641c9a7564a407b691983ad to your computer and use it in GitHub Desktop.
<?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