Last active
December 20, 2018 11:18
-
-
Save patrickmaciel/47e0fb73fddea873e4fac908b8d941a9 to your computer and use it in GitHub Desktop.
Compare arrays multidimensional #php
This file contains hidden or 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; | |
} | |
} else if( !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