public static function unflattenArray($array, $delimiter = '.') {
        if(!is_array($array)) {
            return $array;
        }

        $add = array();

        foreach($array as $key => $value) {
            if(strpos($key, $delimiter) === FALSE) {
                continue;
            }

            $add[] = [ explode($delimiter, $key), $value ];

            unset($array[$key]);
        }

        foreach($add as $pair) {
            $current = &$array;

            while(!is_null($key = array_shift($pair[0]))) {
                if(!is_array($current)) {
                    $current = array();
                }

                if(!array_key_exists($key, $current)) {
                    $current[$key] = array();
                }

                $current = &$current[$key];
            }

            $current = $pair[1];
        }

        return $array;
    }
public static function unflattenArray($array, $delimiter = '.') {
        if(!is_array($array)) {
            return $array;
        }

        $add = array();

        foreach($array as $key => $value) {
            if(strpos($key, $delimiter) === FALSE) {
                continue;
            }

            $add[] = [ explode($delimiter, $key), $value ];

            unset($array[$key]);
        }

        foreach($add as $pair) {
            $current = &$array;

            while(!is_null($key = array_shift($pair[0]))) {
                if(!is_array($current)) {
                    $current = array();
                }

                if(!array_key_exists($key, $current)) {
                    $current[$key] = array();
                }

                $current = &$current[$key];
            }

            $current = $pair[1];
        }

        return $array;
    }
public static function unflattenArray ( $ array , $ delimiter = '.' ) { if ( ! is_array ( $ array ) ) { return $ array ; } $ add = array ( ) ; foreach ( $ array as $ key => $ value ) { if ( strpos ( $ key , $ delimiter ) === FALSE ) { continue ; } $ add [ ] = [ explode ( $ delimiter , $ key ) , $ value ] ; unset ( $ array [ $ key ] ) ; } foreach ( $ add as $ pair ) { $ current = & $ array ; while ( ! is_null ( $ key = array_shift ( $ pair [ 0 ] ) ) ) { if ( ! is_array ( $ current ) ) { $ current = array ( ) ; } if ( ! array_key_exists ( $ key , $ current ) ) { $ current [ $ key ] = array ( ) ; } $ current = & $ current [ $ key ] ; } $ current = $ pair [ 1 ] ; } return $ array ; }
Unflattens an array by a delimiter.

This is particulary useful to pass complex structures via get/post requests from
forms.
Note: Using a json string should also be considered as an alternative.

<code>
use Loops\Misc;

$flatarray = array(
'a'     => 1,
'b.a'   => 2,
'b.b'   => 3
);

Misc::unflattenArray($flatarray);

// $flatarray = array(
//     'a' => 1,
//     'b' => array(
//                'a' => 2,
//                'b' => 3
//            )
//     )
</code>

@param array $array The array that will be unflattened.
@param string $delimiter The used delimiter.
@return array The unflattened array
Unflattens an array by a delimiter .