+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018 |
+ | Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
* Provides a collection of static methods for array manipulation.
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
*/
class CRM_Utils_Array {
self::flatten($value, $flat, $newPrefix, $seperator);
}
else {
- if (!empty($value)) {
- $flat[$newPrefix] = $value;
- }
+ $flat[$newPrefix] = $value;
}
}
}
* This is necessary to preserve sort order when sending an array through json_encode.
*
* @param array $associative
+ * Ex: ['foo' => 'bar'].
* @param string $keyName
+ * Ex: 'key'.
* @param string $valueName
+ * Ex: 'value'.
* @return array
+ * Ex: [0 => ['key' => 'foo', 'value' => 'bar']].
*/
public static function makeNonAssociative($associative, $keyName = 'key', $valueName = 'value') {
$output = array();
* @param string $valueField
* Ex: 'value'.
* @return array
- * Ex: array(
- * 0 => array('key' => 'foo', 'value' => 'bar')
- * ).
+ * @deprecated
*/
public static function toKeyValueRows($array, $keyField = 'key', $valueField = 'value') {
- $result = array();
- foreach ($array as $key => $value) {
- $result[] = array(
- $keyField => $key,
- $valueField => $value,
- );
- }
- return $result;
+ return self::makeNonAssociative($array, $keyField, $valueField);
}
/**
return NULL;
}
- /**
- * Check if a key isset which may be several layers deep.
- *
- * This is a helper for when the calling function does not know how many layers deep the
- * path array is so cannot easily check.
- *
- * @param array $array
- * @param array $path
- * @return bool
- * @deprecated
- */
- public static function recursiveIsset($array, $path) {
- return self::pathIsset($array, $path);
- }
-
- /**
- * Check if a key isset which may be several layers deep.
- *
- * This is a helper for when the calling function does not know how many layers deep the
- * path array is so cannot easily check.
- *
- * @param array $array
- * @param array $path
- * An array of keys - e.g [0, 'bob', 8] where we want to check if $array[0]['bob'][8]
- * @param mixed $default
- * Value to return if not found.
- * @return bool
- * @deprecated
- */
- public static function recursiveValue($array, $path, $default = NULL) {
- return self::pathGet($array, $path, $default);
- }
-
- /**
- * Append the value to the array using the key provided.
- *
- * e.g if value is 'llama' & path is [0, 'email', 'location'] result will be
- * [0 => ['email' => ['location' => 'llama']]
- *
- * @param $path
- * @param $value
- * @param array $source
- *
- * @return array
- * @deprecated
- */
- public static function recursiveBuild($path, $value, $source = []) {
- self::pathSet($source, $path, $value);
- return $source;
- }
-
}