Skip to content

Instantly share code, notes, and snippets.

@makerneo-com
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save makerneo-com/8933387 to your computer and use it in GitHub Desktop.

Select an option

Save makerneo-com/8933387 to your computer and use it in GitHub Desktop.
<?php
$arrayDiff = function($arr1, $arr2) use (&$arrayDiff) {
foreach ($arr1 as $k => $a1) {
if ( ! isset($arr2[$k])) {
continue;
}
if (is_array($arr1[$k])) {
return $arrayDiff($arr1[$k], $arr2[$k]);
} else {
if ((string)$arr1[$k] != (string)$arr2[$k]) {
return array(
'old' => array($k => $arr1[$k]),
'new' => array($k => $arr2[$k]),
);
}
}
}
};
$arr1 = array(
'd'=>23,
'33' => array(
'55'=>1
),
);
$arr2 = array(
'd'=>23,
'33' => array(
'55'=>2
),
);
var_dump($arrayDiff($arr1, $arr2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment