public static function expand($data, $separator = '.')
    {
        $result = array();

        $stack = array();

        foreach ($data as $flat => $value) {
            $keys = explode($separator, $flat);
            $keys = array_reverse($keys);
            $child = array(
                $keys[0] => $value
            );
            array_shift($keys);
            foreach ($keys as $k) {
                $child = array(
                    $k => $child
                );
            }

            $stack[] = array($child, &$result);

            while (!empty($stack)) {
                foreach ($stack as $curKey => &$curMerge) {
                    foreach ($curMerge[0] as $key => &$val) {
                        if (!empty($curMerge[1][$key]) && (array)$curMerge[1][$key] === $curMerge[1][$key] && (array)$val === $val) {
                            $stack[] = array(&$val, &$curMerge[1][$key]);
                        } elseif ((int)$key === $key && isset($curMerge[1][$key])) {
                            $curMerge[1][] = $val;
                        } else {
                            $curMerge[1][$key] = $val;
                        }
                    }
                    unset($stack[$curKey]);
                }
                unset($curMerge);
            }
        }
        return $result;
    }
public static function expand($data, $separator = '.')
    {
        $result = array();

        $stack = array();

        foreach ($data as $flat => $value) {
            $keys = explode($separator, $flat);
            $keys = array_reverse($keys);
            $child = array(
                $keys[0] => $value
            );
            array_shift($keys);
            foreach ($keys as $k) {
                $child = array(
                    $k => $child
                );
            }

            $stack[] = array($child, &$result);

            while (!empty($stack)) {
                foreach ($stack as $curKey => &$curMerge) {
                    foreach ($curMerge[0] as $key => &$val) {
                        if (!empty($curMerge[1][$key]) && (array)$curMerge[1][$key] === $curMerge[1][$key] && (array)$val === $val) {
                            $stack[] = array(&$val, &$curMerge[1][$key]);
                        } elseif ((int)$key === $key && isset($curMerge[1][$key])) {
                            $curMerge[1][] = $val;
                        } else {
                            $curMerge[1][$key] = $val;
                        }
                    }
                    unset($stack[$curKey]);
                }
                unset($curMerge);
            }
        }
        return $result;
    }
public static function expand ( $ data , $ separator = '.' ) { $ result = array ( ) ; $ stack = array ( ) ; foreach ( $ data as $ flat => $ value ) { $ keys = explode ( $ separator , $ flat ) ; $ keys = array_reverse ( $ keys ) ; $ child = array ( $ keys [ 0 ] => $ value ) ; array_shift ( $ keys ) ; foreach ( $ keys as $ k ) { $ child = array ( $ k => $ child ) ; } $ stack [ ] = array ( $ child , & $ result ) ; while ( ! empty ( $ stack ) ) { foreach ( $ stack as $ curKey => & $ curMerge ) { foreach ( $ curMerge [ 0 ] as $ key => & $ val ) { if ( ! empty ( $ curMerge [ 1 ] [ $ key ] ) && ( array ) $ curMerge [ 1 ] [ $ key ] === $ curMerge [ 1 ] [ $ key ] && ( array ) $ val === $ val ) { $ stack [ ] = array ( & $ val , & $ curMerge [ 1 ] [ $ key ] ) ; } elseif ( ( int ) $ key === $ key && isset ( $ curMerge [ 1 ] [ $ key ] ) ) { $ curMerge [ 1 ] [ ] = $ val ; } else { $ curMerge [ 1 ] [ $ key ] = $ val ; } } unset ( $ stack [ $ curKey ] ) ; } unset ( $ curMerge ) ; } } return $ result ; }
Expands a flat array to a nested array.

For example, unflattens an array that was collapsed with `Hash::flatten()`
into a multi-dimensional array. So, `array('0.Foo.Bar' => 'Far')` becomes
`array(array('Foo' => array('Bar' => 'Far')))`.

@param  array  $data      Flattened array
@param  string $separator The delimiter used
@return array
@link   http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html#Hash::expand
Expands a flat array to a nested array .