lithium\util\Set::expand()
Accepts a one-dimensional array where the keys are separated by a delimiter.
Parameters
-
array
$data
The one-dimensional array to expand.
-
array
$options
The options used when expanding the array:
'separator'
string: The delimiter to use when separating keys. Defaults to'.'
.
Returns
arrayReturns a multi-dimensional array expanded from a one dimensional dot-separated array.
Source
public static function expand(array $data, array $options = []) {
$defaults = ['separator' => '.'];
$options += $defaults;
$result = [];
foreach ($data as $key => $val) {
if (strpos($key, $options['separator']) === false) {
if (!isset($result[$key])) {
$result[$key] = $val;
}
continue;
}
list($path, $key) = explode($options['separator'], $key, 2);
$path = is_numeric($path) ? (integer) $path : $path;
$result[$path][$key] = $val;
}
foreach ($result as $key => $value) {
if (is_array($value)) {
$result[$key] = static::expand($value, $options);
}
}
return $result;
}