CRM-14974 Fixed php notice; array_diff does not support multidimensional array diff
authorsunil <esunil.pawar@gmail.com>
Fri, 27 Mar 2015 14:26:13 +0000 (19:56 +0530)
committersunil <esunil.pawar@gmail.com>
Fri, 27 Mar 2015 14:26:13 +0000 (19:56 +0530)
CRM/Core/BAO/Setting.php
CRM/Utils/Array.php

index 6f855ca8d935a4c12ddbd7679279264262ebeaef..e948b5dfc155c4f831af3aaddbf3300b47dfc9e3 100644 (file)
@@ -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 = '';
       }
index ccd56173be8d24e9a2f1424f2eee7c986e6be2d5..fa2bb05654e4ddde417a8ffb20d4939671482c40 100644 (file)
@@ -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;
+  }
 }