public static function asHierarchy(array $array): array
    {
        $hierarchy = [];

        foreach ($array as $key => $value) {
            $segments = explode('.', (string) $key);
            $valueSegment = array_pop($segments);
            $branch = &$hierarchy;

            foreach ($segments as $segment) {
                if (! isset($branch[$segment])) {
                    $branch[$segment] = [];
                }

                $branch = &$branch[$segment];
            }

            $branch[$valueSegment] = $value;
        }

        return $hierarchy;
    }
public static function asHierarchy(array $array): array
    {
        $hierarchy = [];

        foreach ($array as $key => $value) {
            $segments = explode('.', (string) $key);
            $valueSegment = array_pop($segments);
            $branch = &$hierarchy;

            foreach ($segments as $segment) {
                if (! isset($branch[$segment])) {
                    $branch[$segment] = [];
                }

                $branch = &$branch[$segment];
            }

            $branch[$valueSegment] = $value;
        }

        return $hierarchy;
    }
public static function asHierarchy ( array $ array ) : array { $ hierarchy = [ ] ; foreach ( $ array as $ key => $ value ) { $ segments = explode ( '.' , ( string ) $ key ) ; $ valueSegment = array_pop ( $ segments ) ; $ branch = & $ hierarchy ; foreach ( $ segments as $ segment ) { if ( ! isset ( $ branch [ $ segment ] ) ) { $ branch [ $ segment ] = [ ] ; } $ branch = & $ branch [ $ segment ] ; } $ branch [ $ valueSegment ] = $ value ; } return $ hierarchy ; }
Transforms a 1-dimensional array into a multi-dimensional one,
exploding keys according to a separator.

@param array $array

@return array
Transforms a 1 - dimensional array into a multi - dimensional one exploding keys according to a separator .