public static function ArrayConfig::mergeDefaults in Little helpers 7
Same name and namespace in other branches
- 7.2 src/ArrayConfig.php \Drupal\little_helpers\ArrayConfig::mergeDefaults()
Helper functions that recursively merges $defaults into a $config array.
Parameters
array &$config: A config array to merge the defaults into.
array $defaults: The defaults array.
File
- src/
ArrayConfig.php, line 15
Class
Namespace
Drupal\little_helpersCode
public static function mergeDefaults(array &$config, array $defaults) {
$config += $defaults;
foreach ($config as $key => $value) {
if (is_array($value) && isset($defaults[$key]) && is_array($defaults[$key])) {
// Only merge sub-arrays for empty or associative arrays.
$is_assoc = empty($value) || array_keys($value) !== range(0, count($value) - 1);
if ($is_assoc) {
self::mergeDefaults($config[$key], $defaults[$key]);
}
}
}
}