src/Leevel/Http/FileBag.php
protected function normalizeArray(array $elements): array
    {
        $result = [];

        foreach ($elements as $key => $value) {
            if (is_array($value)) {
                if (false === array_key_exists('name', $value)) {
                    $e = 'An uploaded file must be contain key name.';

                    throw new InvalidArgumentException($e);
                }

                if (isset($value['name']) && is_array($value['name'])) {
                    foreach ($value['name'] as $index => $item) {
                        $element = [];

                        foreach (static::$fileKeys as $fileKey) {
                            if (!array_key_exists($fileKey, $value)) {
                                $e = sprintf('An uploaded file must be contain key %s.', $fileKey);

                                throw new InvalidArgumentException($e);
                            }

                            if (!array_key_exists($index, $value[$fileKey])) {
                                $e = sprintf('An uploaded file must be contain %s in key %s.', $index, $fileKey);

                                throw new InvalidArgumentException($e);
                            }

                            $element[$fileKey] = $value[$fileKey][$index] ?? '';
                        }

                        $result[$key.'\\'.$index] = $element;

                        $result = $this->normalizeArray($result);
                    }
                } else {
                    $result[$key] = $value;
                }
            } else {
                $result[$key] = $value;
            }
        }

        return $result;
    }
protected function normalizeArray(array $elements): array
    {
        $result = [];

        foreach ($elements as $key => $value) {
            if (is_array($value)) {
                if (false === array_key_exists('name', $value)) {
                    $e = 'An uploaded file must be contain key name.';

                    throw new InvalidArgumentException($e);
                }

                if (isset($value['name']) && is_array($value['name'])) {
                    foreach ($value['name'] as $index => $item) {
                        $element = [];

                        foreach (static::$fileKeys as $fileKey) {
                            if (!array_key_exists($fileKey, $value)) {
                                $e = sprintf('An uploaded file must be contain key %s.', $fileKey);

                                throw new InvalidArgumentException($e);
                            }

                            if (!array_key_exists($index, $value[$fileKey])) {
                                $e = sprintf('An uploaded file must be contain %s in key %s.', $index, $fileKey);

                                throw new InvalidArgumentException($e);
                            }

                            $element[$fileKey] = $value[$fileKey][$index] ?? '';
                        }

                        $result[$key.'\\'.$index] = $element;

                        $result = $this->normalizeArray($result);
                    }
                } else {
                    $result[$key] = $value;
                }
            } else {
                $result[$key] = $value;
            }
        }

        return $result;
    }
格式化多维数组类文件为一维数组.

@param array $elements

@return array