Recursively converts nested array into a flat one with keys preserving.

@param array  $result    Resulting array
@param array  $array     Source array
@param string $prefix    Key's prefix
@param string $connector Levels connector
503661
protected static function flatArray(array &$result, array $array, $connector = '.', $prefix = null)
    {
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                static::flatArray($result, $value, $connector, $prefix.$key.$connector);
                continue;
            }

            $result[$prefix.$key] = $value;
        }
    }
748213
protected function _makeResult(array $result) {
        return Result::make($result, $this->getClient())->setModelClass($this->_fullModelClass());
    }
528103
public static function flatten(array $array, $parent_prefix = '')
    {
        $flattened = [];

        foreach ($array as $key => $value) {
            $key = $parent_prefix . $key;
            if (is_array($value) && self::isAssoc($value)) {
                $flattened = array_merge(self::flatten($value, $key . '.'), $flattened);
            } else {
                $flattened[$key] = $value;
            }
        }

        return $flattened;
    }
248986
public function prefixArrayKeys($prefix, $array)
    {
        return array_combine(array_map(function ($key) use ($prefix) {
            return $prefix.$key;
        }, array_keys($array)), array_values($array));
    }
58390
private function convertChildren($array, $result)
    {
        if (isset($array['children'])) {
            foreach ($array['children'] as $key => $value) {
                $result['children'][$key] = $this->convertField($value);
                if (isset($result['children'][$key]['required'])) {
                    $result['required'] = $result['required'] || (bool) $result['children'][$key]['required'];
                }
            }

            return $result;
        }

        return $result;
    }
411212
public static function prefixKeys( $prefix, array $data = array() )
    {
        foreach ( static::clean( $data ) as $_key => $_value )
        {
            if ( is_numeric( $_key ) )
            {
                continue;
            }

            if ( is_array( $_value ) )
            {
                $_value = static::prefixKeys( $prefix, $_value );
            }

            $data[$prefix . $_key] = $_value;
            unset( $data[$_key] );
        }

        return $data;
    }
678940
public static function CleanPrefixedkeyInAssocArray($array, $prefix = "\0*\0") {
        $cleanedArray = array("array");
        foreach ($array as $key => $value) {
            $keyCleaned = str_replace($prefix, "", $key);
            $cleanedArray["array"][$keyCleaned] = $value;
        }
        return $cleanedArray["array"];
    }
546267
public static function recursiveImplode($glue, array $array)
    {
        $return = '';
        $index  = 0;
        $count  = count($array);

        foreach ($array as $piece) {
            if (is_array($piece)) {
                $return .= self::recursiveImplode($glue, $piece);
            } else {
                $return .= $piece;
            }

            if ($index < $count - 1) {
                $return .= $glue;
            }
            ++$index;
        }

        return $return;
    }
631786
public static function values($array, $prefix = null)
    {
        $values = array_values($array);

        if (! empty($prefix)) {
            $values = static::prefix($values, $prefix);
        }

        return $values;
    }
1011884
protected function dotify(array $data, $result = array(), $key = '')
    {
        foreach ((array) $data as $name => $value)
        {
            if (is_array($value) && empty($value) === false)
            {
                $text = (string) $key . $name . '.';

                $item = $this->dotify($value, $result, $text);

                $result = array_merge($result, $item);

                continue;
            }

            $result[$key . $name] = $value;
        }

        return $result;
    }
215686
protected function _flattenMultiDimensionalParams($arrays, $prefix = null)
    {
        $new = array();

        if (is_object($arrays)) {
            $arrays = get_object_vars($arrays);
        }

        foreach ($arrays as $key => $value) {
            $k =
                isset($prefix) ?
                    $prefix . '[' . $key . ']' :
                    $key;

            if (is_array($value) || is_object($value)) {
                $new =
                    array_merge(
                        $new,
                        $this->_flattenMultiDimensionalParams($value, $k)
                    );
            } else {
                $new[$k] = $value;
            }
        }

        return $new;
    }
1367623
private function createArrayLines(array $data, $prefix = '')
    {
        $content = '';

        foreach ($data as $key => $value) {
            $newKey = "{$prefix}[$key]";

            if (is_array($value)) {
                $content .= $this->createArrayLines($value, $newKey);
                continue;
            }

            $content .= $this->createPropertyLine($newKey, $value);
        }

        return $content;
    }
318769
private function renderArray($array, $prefixLines)
    {
        $isAssociativeArray = Piwik::isAssociativeArray($array);

        // check if array contains arrays, and if not wrap the result in an extra <row> element
        // (only check if this is the root renderArray call)
        // NOTE: this is for backwards compatibility. before, array's were added to a new DataTable.
        // if the array had arrays, they were added as multiple rows, otherwise it was treated as
        // one row. removing will change API output.
        $wrapInRow = $prefixLines === "\t"
            && self::shouldWrapArrayBeforeRendering($array, $wrapSingleValues = false, $isAssociativeArray);

        // render the array
        $result = "";
        if ($wrapInRow) {
            $result .= "$prefixLines<row>\n";
            $prefixLines .= "\t";
        }
        foreach ($array as $key => $value) {
            // based on the type of array & the key, determine how this node will look
            if ($isAssociativeArray) {
                if (strpos($key, '=') !== false) {
                    list($keyAttributeName, $key) = explode('=', $key, 2);

                    $prefix = "<row $keyAttributeName=\"$key\">";
                    $suffix = "</row>";
                    $emptyNode = "<row $keyAttributeName=\"$key\">";
                } elseif (!self::isValidXmlTagName($key)) {
                    $prefix = "<row key=\"$key\">";
                    $suffix = "</row>";
                    $emptyNode = "<row key=\"$key\"/>";
                } else {
                    $prefix = "<$key>";
                    $suffix = "</$key>";
                    $emptyNode = "<$key />";
                }
            } else {
                $prefix = "<row>";
                $suffix = "</row>";
                $emptyNode = "<row/>";
            }

            // render the array item
            if (is_array($value) || $value instanceof \stdClass) {
                $result .= $prefixLines . $prefix . "\n";
                $result .= $this->renderArray((array) $value, $prefixLines . "\t");
                $result .= $prefixLines . $suffix . "\n";
            } elseif ($value instanceof DataTable
                || $value instanceof Map
            ) {
                if ($value->getRowsCount() == 0) {
                    $result .= $prefixLines . $emptyNode . "\n";
                } else {
                    $result .= $prefixLines . $prefix . "\n";
                    if ($value instanceof Map) {
                        $result .= $this->renderDataTableMap($value, $this->getArrayFromDataTable($value), $prefixLines);
                    } elseif ($value instanceof Simple) {
                        $result .= $this->renderDataTableSimple($this->getArrayFromDataTable($value), $prefixLines);
                    } else {
                        $result .= $this->renderDataTable($this->getArrayFromDataTable($value), $prefixLines);
                    }
                    $result .= $prefixLines . $suffix . "\n";
                }
            } else {
                $xmlValue = self::formatValueXml($value);

                if (strlen($xmlValue) != 0) {
                    $result .= $prefixLines . $prefix . $xmlValue . $suffix . "\n";
                } else {
                    $result .= $prefixLines . $emptyNode . "\n";
                }
            }
        }
        if ($wrapInRow) {
            $result .= substr($prefixLines, 0, strlen($prefixLines) - 1) . "</row>\n";
        }
        return $result;
    }
305710
protected function flattenArray(array $body, $prefix = '')
    {
        $newBody = array();
        foreach ($body as $k => $v) {
            $key = (!strlen($prefix)) ? $k : "{$prefix}[{$k}]";
            if (is_array($v)) {
                $newBody += $this->flattenArray($v, $key);
            } else {
                $newBody[$key] = $v;
            }
        }
        return $newBody;
    }
924317
public static function sortCol($result,$array)
    {
        foreach ($result as $key => $fields) {
         $dados[] = self::sortkeys($fields,$array);
        }

        if(!$dados){ $dados = [];}

        return $dados;
    }
988464
private function parseSetResultNodes(DOMElement $child, $name, array &$result = null)
    {
        if (!(is_array($result[$name]) && $this->valueIsList($result[$name]))) {
            return false;
        }

        $value = static::getPhpValue($child, null, $this);

        if (is_array($value) && $this->valueIsList($value)) {
            return $result[$name] = array_merge($result[$name], $value);
        }

        return $result[$name][] = $value;
    }
23675
private static function flatten(array $array, &$output): void
    {
        if (null === $output) {
            $output = [];
        }

        foreach ($array as $key => $value) {
            if (\is_array($value)) {
                self::flatten($value, $output);

                continue;
            }

            $output[$key] = $value;
        }
    }