public static function untangleFilesArray(array $convolutedFiles): array
    {
        $untangledFiles = [];

        $fieldPaths = [];
        foreach ($convolutedFiles as $firstLevelFieldName => $fieldInformation) {
            if (!is_array($fieldInformation['error'])) {
                $fieldPaths[] = [$firstLevelFieldName];
            } else {
                $newFieldPaths = self::calculateFieldPathsAsArray($fieldInformation['error'], $firstLevelFieldName);
                $fieldPaths = array_merge($fieldPaths, $newFieldPaths);
            }
        }

        foreach ($fieldPaths as $fieldPath) {
            if (count($fieldPath) === 1) {
                $fileInformation = $convolutedFiles[$fieldPath{0}];
            } else {
                $fileInformation = [];
                foreach ($convolutedFiles[$fieldPath{0}] as $key => $subStructure) {
                    $fileInformation[$key] = Arrays::getValueByPath($subStructure, array_slice($fieldPath, 1));
                }
            }
            if (isset($fileInformation['error']) && $fileInformation['error'] !== \UPLOAD_ERR_NO_FILE) {
                $untangledFiles = Arrays::setValueByPath($untangledFiles, $fieldPath, $fileInformation);
            }
        }

        return $untangledFiles;
    }
public static function untangleFilesArray(array $convolutedFiles): array
    {
        $untangledFiles = [];

        $fieldPaths = [];
        foreach ($convolutedFiles as $firstLevelFieldName => $fieldInformation) {
            if (!is_array($fieldInformation['error'])) {
                $fieldPaths[] = [$firstLevelFieldName];
            } else {
                $newFieldPaths = self::calculateFieldPathsAsArray($fieldInformation['error'], $firstLevelFieldName);
                $fieldPaths = array_merge($fieldPaths, $newFieldPaths);
            }
        }

        foreach ($fieldPaths as $fieldPath) {
            if (count($fieldPath) === 1) {
                $fileInformation = $convolutedFiles[$fieldPath{0}];
            } else {
                $fileInformation = [];
                foreach ($convolutedFiles[$fieldPath{0}] as $key => $subStructure) {
                    $fileInformation[$key] = Arrays::getValueByPath($subStructure, array_slice($fieldPath, 1));
                }
            }
            if (isset($fileInformation['error']) && $fileInformation['error'] !== \UPLOAD_ERR_NO_FILE) {
                $untangledFiles = Arrays::setValueByPath($untangledFiles, $fieldPath, $fileInformation);
            }
        }

        return $untangledFiles;
    }
public static function untangleFilesArray ( array $ convolutedFiles ) : array { $ untangledFiles = [ ] ; $ fieldPaths = [ ] ; foreach ( $ convolutedFiles as $ firstLevelFieldName => $ fieldInformation ) { if ( ! is_array ( $ fieldInformation [ 'error' ] ) ) { $ fieldPaths [ ] = [ $ firstLevelFieldName ] ; } else { $ newFieldPaths = self :: calculateFieldPathsAsArray ( $ fieldInformation [ 'error' ] , $ firstLevelFieldName ) ; $ fieldPaths = array_merge ( $ fieldPaths , $ newFieldPaths ) ; } } foreach ( $ fieldPaths as $ fieldPath ) { if ( count ( $ fieldPath ) === 1 ) { $ fileInformation = $ convolutedFiles [ $ fieldPath { 0 } ] ; } else { $ fileInformation = [ ] ; foreach ( $ convolutedFiles [ $ fieldPath { 0 } ] as $ key => $ subStructure ) { $ fileInformation [ $ key ] = Arrays :: getValueByPath ( $ subStructure , array_slice ( $ fieldPath , 1 ) ) ; } } if ( isset ( $ fileInformation [ 'error' ] ) && $ fileInformation [ 'error' ] !== \ UPLOAD_ERR_NO_FILE ) { $ untangledFiles = Arrays :: setValueByPath ( $ untangledFiles , $ fieldPath , $ fileInformation ) ; } } return $ untangledFiles ; }
Transforms the convoluted _FILES superglobal into a manageable form.

@param array $convolutedFiles The _FILES superglobal or something with the same structure
@return array Untangled files
Transforms the convoluted _FILES superglobal into a manageable form .