Last active
October 18, 2017 14:27
-
-
Save Ellrion/e703a97e27290250dcc5 to your computer and use it in GitHub Desktop.
array_diff_assoc_recursive helper
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($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