private static function ArrayConverter::getElementByPath in Plug 7
1 call to ArrayConverter::getElementByPath()
- ArrayConverter::expandToTree in lib/Symfony/translation/Util/ArrayConverter.php
- Converts linear messages array to tree-like array.
For example this rray('foo.bar' => 'value') will be converted to array('foo' => array('bar' => 'value')).
File
- lib/Symfony/translation/Util/ArrayConverter.php, line 51
Class
- ArrayConverter
- ArrayConverter generates tree like structure from a message catalogue.
e.g. this
'foo.bar1' => 'test1',
'foo.bar2' => 'test2'
converts to follows:
foo:
bar1: test1
bar2: test2.
Namespace
Symfony\Component\Translation\Util
Code
private static function &getElementByPath(array &$tree, array $parts) {
$elem =& $tree;
$parentOfElem = null;
foreach ($parts as $i => $part) {
if (isset($elem[$part]) && is_string($elem[$part])) {
$elem =& $elem[implode('.', array_slice($parts, $i))];
break;
}
$parentOfElem =& $elem;
$elem =& $elem[$part];
}
if (is_array($elem) && count($elem) > 0 && $parentOfElem) {
self::cancelExpand($parentOfElem, $part, $elem);
}
return $elem;
}