| 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.
* (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) {
*
* @return array
* Array-encoded tree
- *
*/
public function unflatten($delim, &$arr) {
$result = 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) {
*
* @return bool
* True if $value was found, false otherwise.
- *
*/
public static function crmInArray($value, $params, $caseInsensitive = TRUE) {
foreach ($params as $item) {
}
/**
- * 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
* @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()) {
* @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.
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])) {
$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;
foreach ($records as $key => $record) {
if (is_object($record)) {
$result[$key] = $record->{$prop};
- } else {
+ }
+ else {
$result[$key] = $record[$prop];
}
}
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
* @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));
* @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)) {
}
/**
- * Get the first element of an array
+ * Get the first element of an array.
*
* @param array $array
* @return mixed|NULL
* 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) {
}
return $output;
}
+
}