From 06d253f5e668e95ce3683f02417e9c320d509eb6 Mon Sep 17 00:00:00 2001 From: sunil Date: Fri, 27 Mar 2015 19:56:13 +0530 Subject: [PATCH] CRM-14974 Fixed php notice; array_diff does not support multidimensional array diff --- CRM/Core/BAO/Setting.php | 2 +- CRM/Utils/Array.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CRM/Core/BAO/Setting.php b/CRM/Core/BAO/Setting.php index 6f855ca8d9..e948b5dfc1 100644 --- a/CRM/Core/BAO/Setting.php +++ b/CRM/Core/BAO/Setting.php @@ -245,7 +245,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { if ($group && !isset($name) && $cacheKey) { // check value against the cache, and unset key if values are different - $valueDifference = array_diff($overrideGroup, self::$_cache[$cacheKey]); + $valueDifference = CRM_Utils_Array::multiArrayDiff($overrideGroup, self::$_cache[$cacheKey]); if (!empty($valueDifference)) { $cacheKey = ''; } diff --git a/CRM/Utils/Array.php b/CRM/Utils/Array.php index ccd56173be..fa2bb05654 100644 --- a/CRM/Utils/Array.php +++ b/CRM/Utils/Array.php @@ -831,4 +831,34 @@ class CRM_Utils_Array { return $output; } + /** + * Diff multidimensional arrays + * ( array_diff does not support multidimensional array) + * + * @param array $array1 + * @param array $array2 + * @return array + */ + public static function multiArrayDiff($array1, $array2) { + $arrayDiff = array(); + foreach ($array1 as $mKey => $mValue) { + if (array_key_exists($mKey, $array2)) { + if (is_array($mValue)) { + $recursiveDiff = self::multiArrayDiff($mValue, $array2[$mKey]); + if (count($recursiveDiff)) { + $arrayDiff[$mKey] = $recursiveDiff; + } + } + else { + if ($mValue != $array2[$mKey]) { + $arrayDiff[$mKey] = $mValue; + } + } + } + else { + $arrayDiff[$mKey] = $mValue; + } + } + return $arrayDiff; + } } -- 2.25.1