Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-02-09-11-44-07
[civicrm-core.git] / CRM / Utils / Array.php
index 1f6791bd6fa765f1ae607dc6806ef2c37f85d994..9471cb0fa2f0b86f6e0040fc4a8bcd5397b2e357 100644 (file)
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  * Provides a collection of static methods for array manipulation.
@@ -231,7 +231,6 @@ class CRM_Utils_Array {
    *   (optional) String to prepend to keys.
    * @param string $seperator
    *   (optional) String that separates the concatenated keys.
-   *
    */
   public static function flatten(&$list, &$flat, $prefix = '', $seperator = ".") {
     foreach ($list as $name => $value) {
@@ -259,7 +258,6 @@ class CRM_Utils_Array {
    *
    * @return array
    *   Array-encoded tree
-   *
    */
   public function unflatten($delim, &$arr) {
     $result = array();
@@ -349,7 +347,8 @@ class CRM_Utils_Array {
   /**
    * @param $subset
    * @param $superset
-   * @return bool TRUE if $subset is a subset of $superset
+   * @return bool
+   *   TRUE if $subset is a subset of $superset
    */
   public static function isSubset($subset, $superset) {
     foreach ($subset as $expected) {
@@ -372,7 +371,6 @@ class CRM_Utils_Array {
    *
    * @return bool
    *   True if $value was found, false otherwise.
-   *
    */
   public static function crmInArray($value, $params, $caseInsensitive = TRUE) {
     foreach ($params as $item) {
@@ -390,7 +388,7 @@ class CRM_Utils_Array {
   }
 
   /**
-   * This function is used to convert associative array names to values
+   * convert associative array names to values.
    * and vice-versa.
    *
    * This function is used by both the web form layer and the api. Note that
@@ -442,7 +440,7 @@ class CRM_Utils_Array {
    * @param array $array
    *   (optional) Array to be checked for emptiness.
    *
-   * @return boolean
+   * @return bool
    *   True if the array is empty.
    */
   public static function crmIsEmptyArray($array = array()) {
@@ -533,23 +531,23 @@ class CRM_Utils_Array {
    * @param array $items
    *   The array from which to remove items.
    *
-   * @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.
+   * Additional params:
+   *   When passed a string, unsets $items[$key].
+   *   When passed an array of strings, unsets $items[$k] for each string $k in the array.
    */
-   public static function remove(&$items) {
-     foreach (func_get_args() as $n => $key) {
-       // Skip argument 0 ($items) by testing $n for truth.
-       if ($n && is_array($key)) {
-         foreach($key as $k) {
-           unset($items[$k]);
-         }
-       }
-       elseif ($n) {
-         unset($items[$key]);
-       }
-     }
-   }
+  public static function remove(&$items) {
+    foreach (func_get_args() as $n => $key) {
+      // Skip argument 0 ($items) by testing $n for truth.
+      if ($n && is_array($key)) {
+        foreach ($key as $k) {
+          unset($items[$k]);
+        }
+      }
+      elseif ($n) {
+        unset($items[$key]);
+      }
+    }
+  }
 
   /**
    * Builds an array-tree which indexes the records in an array.
@@ -570,7 +568,8 @@ class CRM_Utils_Array {
       foreach ($keys as $key) {
         if (is_array($record)) {
           $keyvalue = isset($record[$key]) ? $record[$key] : NULL;
-        } else {
+        }
+        else {
           $keyvalue = isset($record->{$key}) ? $record->{$key} : NULL;
         }
         if (isset($node[$keyvalue]) && !is_array($node[$keyvalue])) {
@@ -579,9 +578,10 @@ class CRM_Utils_Array {
         $node = &$node[$keyvalue];
       }
       if (is_array($record)) {
-        $node[ $record[$final_key] ] = $record;
-      } else {
-        $node[ $record->{$final_key} ] = $record;
+        $node[$record[$final_key]] = $record;
+      }
+      else {
+        $node[$record->{$final_key}] = $record;
       }
     }
     return $result;
@@ -604,7 +604,8 @@ class CRM_Utils_Array {
       foreach ($records as $key => $record) {
         if (is_object($record)) {
           $result[$key] = $record->{$prop};
-        } else {
+        }
+        else {
           $result[$key] = $record[$prop];
         }
       }
@@ -701,7 +702,7 @@ class CRM_Utils_Array {
     return $elementArray;
   }
 
-  /*
+  /**
    * Searches array keys by regex, returning the value of the first match.
    *
    * Given a regular expression and an array, this method searches the keys
@@ -722,13 +723,6 @@ class CRM_Utils_Array {
    * @return mixed
    *   The value found.
    */
-  /**
-   * @param $regexKey
-   * @param $list
-   * @param null $default
-   *
-   * @return null
-   */
   public static function valueByRegexKey($regexKey, $list, $default = NULL) {
     if (is_array($list) && $regexKey) {
       $matches = preg_grep($regexKey, array_keys($list));
@@ -750,18 +744,18 @@ class CRM_Utils_Array {
    * @return array
    *   Each item is a distinct combination of values from $dimensions.
    *
-   * For example, the product of
-   * {
+   *   For example, the product of
+   *   {
    *   fg => {red, blue},
    *   bg => {white, black}
-   * }
-   * would be
-   * {
+   *   }
+   *   would be
+   *   {
    *   {fg => red, bg => white},
    *   {fg => red, bg => black},
    *   {fg => blue, bg => white},
    *   {fg => blue, bg => black}
-   * }
+   *   }
    */
   public static function product($dimensions, $template = array()) {
     if (empty($dimensions)) {
@@ -787,7 +781,7 @@ class CRM_Utils_Array {
   }
 
   /**
-   * Get the first element of an array
+   * Get the first element of an array.
    *
    * @param array $array
    * @return mixed|NULL
@@ -806,7 +800,8 @@ class CRM_Utils_Array {
    * not appear in the result.
    *
    * @param array $array
-   * @param array $keys list of keys to copy
+   * @param array $keys
+   *   List of keys to copy.
    * @return array
    */
   public static function subset($array, $keys) {
@@ -835,4 +830,5 @@ class CRM_Utils_Array {
     }
     return $output;
   }
+
 }