Merge pull request #3516 from jitendrapurohit/CRM-14869
[civicrm-core.git] / CRM / Utils / Array.php
index 458d45d9935aeae4df36e140d0497f401ce7c4b8..af0900da1e12e71fe8cf363b082d477612d39bd7 100644 (file)
@@ -198,7 +198,7 @@ class CRM_Utils_Array {
    *             [1] => baz
    *             [2] => 42
    *         )
-   * 
+   *
    *     [asdf] => Array
    *         (
    *             [merp] => bleep
@@ -208,12 +208,12 @@ class CRM_Utils_Array {
    *                     [1] => 2
    *                     [2] => 3
    *                 )
-   * 
+   *
    *         )
-   * 
+   *
    *     [quux] => 999
    * )
-   * 
+   *
    * Corresponding flattened array:
    * Array
    * (
@@ -354,6 +354,20 @@ class CRM_Utils_Array {
     return FALSE;
   }
 
+  /**
+   * @param $subset
+   * @param $superset
+   * @return bool TRUE if $subset is a subset of $superset
+   */
+  static function isSubset($subset, $superset) {
+    foreach ($subset as $expected) {
+      if (!in_array($expected, $superset)) {
+        return FALSE;
+      }
+    }
+    return TRUE;
+  }
+
   /**
    * Recursively copies all values of an array into a new array.
    *
@@ -367,6 +381,10 @@ class CRM_Utils_Array {
    * @params int $depth
    *   (optional) Current recursion depth.
    *
+   * @param $array
+   * @param int $maxdepth
+   * @param int $depth
+   *
    * @return array
    *   The new copy of $array.
    *
@@ -589,7 +607,7 @@ class CRM_Utils_Array {
    * @param string $field
    *   Name of the attribute used for sorting.
    *
-   * @return array 
+   * @return array
    *   Sorted array
    */
   static function crmArraySortByField($array, $field) {
@@ -604,7 +622,7 @@ class CRM_Utils_Array {
    * @param array $array
    *   The input array possibly containing duplicate values.
    *
-   * @return array 
+   * @return array
    *   The input array with duplicate values removed.
    */
   static function crmArrayUnique($array) {
@@ -628,7 +646,7 @@ class CRM_Utils_Array {
    * @param array $array
    *   (optional) Array to be sorted.
    *
-   * @return array 
+   * @return array
    *   Sorted array.
    */
   static function asort($array = array()) {
@@ -651,8 +669,8 @@ class CRM_Utils_Array {
    *
    * @param array $items
    *   The array from which to remove items.
-   * @param string[]|string $key,...
-   *   When passed a string, unsets $items[$key].
+   *
+   * @internal param string|\string[] $key When passed a string, unsets $items[$key].*   When passed a string, unsets $items[$key].
    *   When passed an array of strings, unsets $items[$k] for each string $k
    *   in the array.
    */
@@ -688,9 +706,9 @@ class CRM_Utils_Array {
       $node = &$result;
       foreach ($keys as $key) {
         if (is_array($record)) {
-          $keyvalue = $record[$key];
+          $keyvalue = isset($record[$key]) ? $record[$key] : NULL;
         } else {
-          $keyvalue = $record->{$key};
+          $keyvalue = isset($record->{$key}) ? $record->{$key} : NULL;
         }
         if (isset($node[$keyvalue]) && !is_array($node[$keyvalue])) {
           $node[$keyvalue] = array();
@@ -860,6 +878,13 @@ class CRM_Utils_Array {
    * @return mixed
    *   The value found.
    */
+  /**
+   * @param $regexKey
+   * @param $list
+   * @param null $default
+   *
+   * @return null
+   */
   static function valueByRegexKey($regexKey, $list, $default = NULL) {
     if (is_array($list) && $regexKey) {
       $matches = preg_grep($regexKey, array_keys($list));