Skip to content

Instantly share code, notes, and snippets.

@vincenzodibiaggio
Created July 10, 2013 10:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vincenzodibiaggio/5965342 to your computer and use it in GitHub Desktop.
Save vincenzodibiaggio/5965342 to your computer and use it in GitHub Desktop.
php array diff recursive (from php.net site)
private function arrayRecursiveDiff($aArray1, $aArray2) {
$aReturn = array();
foreach ($aArray1 as $mKey => $mValue) {
if (array_key_exists($mKey, $aArray2)) {
if (is_array($mValue)) {
$aRecursiveDiff = $this->arrayRecursiveDiff($mValue, $aArray2[$mKey]);
if (count($aRecursiveDiff)) { $aReturn[$mKey] = $aRecursiveDiff; }
} else {
if ($mValue != $aArray2[$mKey]) {
$aReturn[$mKey] = $mValue;
}
}
} else {
$aReturn[$mKey] = $mValue;
}
}
return $aReturn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment