public static function toNested(array $flat, $delimiter = '.')
    {
        $tree = [];

        foreach ($flat as $key => $val) {

            // Get parent parts and the current leaf
            $parts = static::splitPath($key, $delimiter);
            $leafPart = array_pop($parts);

            // Build parent structure
            $parent = &$tree;

            foreach ($parts as $part) {
                if (!isset($parent[$part])) {
                    $parent[$part] = [];
                } elseif (!is_array($parent[$part])) {
                    $parent[$part] = [];
                }

                $parent = &$parent[$part];
            }

            // Add the final part to the structure
            if (empty($parent[$leafPart])) {
                $parent[$leafPart] = $val;
            }
        }

        return $tree;
    }
public static function toNested(array $flat, $delimiter = '.')
    {
        $tree = [];

        foreach ($flat as $key => $val) {

            // Get parent parts and the current leaf
            $parts = static::splitPath($key, $delimiter);
            $leafPart = array_pop($parts);

            // Build parent structure
            $parent = &$tree;

            foreach ($parts as $part) {
                if (!isset($parent[$part])) {
                    $parent[$part] = [];
                } elseif (!is_array($parent[$part])) {
                    $parent[$part] = [];
                }

                $parent = &$parent[$part];
            }

            // Add the final part to the structure
            if (empty($parent[$leafPart])) {
                $parent[$leafPart] = $val;
            }
        }

        return $tree;
    }
public static function toNested ( array $ flat , $ delimiter = '.' ) { $ tree = [ ] ; foreach ( $ flat as $ key => $ val ) { // Get parent parts and the current leaf $ parts = static :: splitPath ( $ key , $ delimiter ) ; $ leafPart = array_pop ( $ parts ) ; // Build parent structure $ parent = & $ tree ; foreach ( $ parts as $ part ) { if ( ! isset ( $ parent [ $ part ] ) ) { $ parent [ $ part ] = [ ] ; } elseif ( ! is_array ( $ parent [ $ part ] ) ) { $ parent [ $ part ] = [ ] ; } $ parent = & $ parent [ $ part ] ; } // Add the final part to the structure if ( empty ( $ parent [ $ leafPart ] ) ) { $ parent [ $ leafPart ] = $ val ; } } return $ tree ; }
Direct access to the "array-nester". Put a flat array in this method
and it will return a recursivly nested version.

@param array  $flat
@param string $delimiter

@return array
Direct access to the array - nester . Put a flat array in this method and it will return a recursivly nested version .