Merge remote-tracking branch 'upstream/4.3' into 4.3-4.4-2013-10-28-14-52-15
[civicrm-core.git] / CRM / Utils / Array.php
index 36af8fca232e06d43ee003580a07073bf1fabc80..296f470a0024e07105bd12c6a882cd0b6f39f746 100644 (file)
@@ -622,5 +622,18 @@ class CRM_Utils_Array {
     $elementArray = array_combine($keys, array_values($elementArray));
     return $elementArray;
   }
+
+  /*
+   * function to get value of first matched
+   * regex key element of an array
+   */
+  static function valueByRegexKey($regexKey, $list, $default = NULL) {
+    if (is_array($list) && $regexKey) {
+      $matches = preg_grep($regexKey, array_keys($list));
+      $key = reset($matches);
+      return ($key && array_key_exists($key, $list)) ? $list[$key] : $default;
+    }
+    return $default;
+  }
 }