public static function htmlArrayFlatten($array_to_flatten, $parents = array ())
    {
        // Returns an array that has been "flattened", suitable for use in html forms.

        $flattened = array ();

        foreach ($array_to_flatten as $key => $value) {
            if (is_array($value)) {
                // Ugly hack. We cannot alter our $parents array, but must pass the proper array to the recursive function.
                // PHP provides no easy way to do this.
                $parent_with_child = $parents;
                $parent_with_child[] = $key;
                $flattened = array_merge($flattened, self::htmlArrayFlatten($value, $parent_with_child));
            } else {
                $keystr = '';

                // If we have parents, build the key
                if (count($parents) > 0) {

                    // Extract the common parts
                    if (!isset ($parentstr)) {
                        // First parent is rendered as Parent
                        reset($parents);
                        list (, $parentstr) = each($parents);

                        // Children build the string as Parent[Child][Child]..
                        while (list (, $parent) = each($parents)) {
                            $parentstr .= "[$parent]";
                        }
                    }

                    // Finally, identify the current key to build Parent[Child][...][0]
                    $keystr = $parentstr . "[$key]";

                } else {
                    // With no parents, the key name is just Key
                    $keystr = $key;
                }

                $flattened[$keystr] = $value;
            }

        }

        return $flattened;
    }
public static function htmlArrayFlatten($array_to_flatten, $parents = array ())
    {
        // Returns an array that has been "flattened", suitable for use in html forms.

        $flattened = array ();

        foreach ($array_to_flatten as $key => $value) {
            if (is_array($value)) {
                // Ugly hack. We cannot alter our $parents array, but must pass the proper array to the recursive function.
                // PHP provides no easy way to do this.
                $parent_with_child = $parents;
                $parent_with_child[] = $key;
                $flattened = array_merge($flattened, self::htmlArrayFlatten($value, $parent_with_child));
            } else {
                $keystr = '';

                // If we have parents, build the key
                if (count($parents) > 0) {

                    // Extract the common parts
                    if (!isset ($parentstr)) {
                        // First parent is rendered as Parent
                        reset($parents);
                        list (, $parentstr) = each($parents);

                        // Children build the string as Parent[Child][Child]..
                        while (list (, $parent) = each($parents)) {
                            $parentstr .= "[$parent]";
                        }
                    }

                    // Finally, identify the current key to build Parent[Child][...][0]
                    $keystr = $parentstr . "[$key]";

                } else {
                    // With no parents, the key name is just Key
                    $keystr = $key;
                }

                $flattened[$keystr] = $value;
            }

        }

        return $flattened;
    }
public static function htmlArrayFlatten ( $ array_to_flatten , $ parents = array ( ) ) { // Returns an array that has been "flattened", suitable for use in html forms. $ flattened = array ( ) ; foreach ( $ array_to_flatten as $ key => $ value ) { if ( is_array ( $ value ) ) { // Ugly hack. We cannot alter our $parents array, but must pass the proper array to the recursive function. // PHP provides no easy way to do this. $ parent_with_child = $ parents ; $ parent_with_child [ ] = $ key ; $ flattened = array_merge ( $ flattened , self :: htmlArrayFlatten ( $ value , $ parent_with_child ) ) ; } else { $ keystr = '' ; // If we have parents, build the key if ( count ( $ parents ) > 0 ) { // Extract the common parts if ( ! isset ( $ parentstr ) ) { // First parent is rendered as Parent reset ( $ parents ) ; list ( , $ parentstr ) = each ( $ parents ) ; // Children build the string as Parent[Child][Child].. while ( list ( , $ parent ) = each ( $ parents ) ) { $ parentstr .= "[$parent]" ; } } // Finally, identify the current key to build Parent[Child][...][0] $ keystr = $ parentstr . "[$key]" ; } else { // With no parents, the key name is just Key $ keystr = $ key ; } $ flattened [ $ keystr ] = $ value ; } } return $ flattened ; }
Returns an array that has been "flattened", suitable for use in html forms.

For example, an array like ['cache' => 'Craig', 'Fusion' => ['data' => 'fed', 'foo' => 'bar']]
becomes ['cache' => 'Craig', 'Fusion[data]' => 'fed', 'Fusion[foo]' => 'bar']

@param array $array_to_flatten Array to flatten
@param array $parents          [NEVER SPECIFY] Only used when called recursively. Ignore this parameter

@return array An array containing only keys and values, suitable to display on forms.
Returns an array that has been flattened suitable for use in html forms .