Skip to content

Instantly share code, notes, and snippets.

@Ellrion
Last active October 18, 2017 14:27
Show Gist options
  • Save Ellrion/e703a97e27290250dcc5 to your computer and use it in GitHub Desktop.
Save Ellrion/e703a97e27290250dcc5 to your computer and use it in GitHub Desktop.
array_diff_assoc_recursive helper
<?php
function array_diff_assoc_recursive($aArray1, $aArray2) {
$aReturn = array();
foreach ($aArray1 as $mKey => $mValue) {
if (! array_key_exists($mKey, $aArray2)) {
$aReturn[$mKey] = $mValue;
continue;
}
if (is_array($mValue)) {
$aRecursiveDiff = array_diff_assoc_recursive($mValue, $aArray2[$mKey]);
if (count($aRecursiveDiff)) {
$aReturn[$mKey] = $aRecursiveDiff;
}
} elseif ((string)$mValue !== (string)$aArray2[$mKey]) {
$aReturn[$mKey] = $mValue;
}
}
return $aReturn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment