An internal method we use that comes in handy elsewhere as well.

@param array $files An array of files that share a common directory somewhere.

@return string The common directory (with trailing slash) shared amongst your $files.
189847
public function commonDir(array $files)
    {
        $files = array_values($files);
        $cut = 0;
        $count = count($files);
        $shortest = min(array_map('mb_strlen', $files));
        while ($cut < $shortest) {
            $char = $files[0][$cut];
            for ($i = 1; $i < $count; ++$i) {
                if ($files[$i][$cut] !== $char) {
                    break 2;
                }
            }
            ++$cut;
        }
        $dir = mb_substr($files[0], 0, $cut);
        if (false !== $slash = mb_strrpos($dir, '/')) {
            $dir = mb_substr($dir, 0, $slash + 1);
        } elseif (false !== $slash = mb_strrpos($dir, '\\')) {
            $dir = mb_substr($dir, 0, $slash + 1);
        } else {
            $dir = ''; // no common folder
        }

        return $dir; // with trailing slash (if any)
    }
863962
protected function getCountForFiles(array $files)
    {
        $analyserClass = '\\SebastianBergmann\\PHPLOC\\Analyser';
        $analyser = new $analyserClass();

        return $analyser->countFiles($files, $this->countTests);
    }
1028688
protected function generateInfo($files)
	{
		if ($this->documentRootDir)
			$dr = $this->documentRootDir;
		else
			$dr = $_SERVER["DOCUMENT_ROOT"];


		$mtimes = "";
		$fileList = array();

		foreach ($files as $file)
		{
			$file = $dr . trim($file);
			if (!is_file($file))
				throw new \Exception ( "File '{$file}' doesn't exist" );
			else
			{
				$mtimes .= filemtime($file);
				$fileList[] = $file;
			}
		}

		$mtimes = md5($mtimes);
		return array($mtimes, $fileList);
	}
712299
protected function GenerateFrameworkFile($files) {
        $filePath = $this->GenerateConstantsClass($files);
        array_push($this->filesGenerated, $filePath);
        return $filePath;
    }
431566
protected static function normalizeNested(array $files)
    {
        $normalized = [];
        foreach (array_keys($files['tmp_name']) as $key) {
            $spec = [
                'name'     => $files['name'][$key],
                'tmp_name' => $files['tmp_name'][$key],
                'type'     => $files['type'][$key],
                'size'     => $files['size'][$key],
                'error'    => $files['error'][$key],
            ];
            $normalized[$key] = static::build($spec);
        }

        return $normalized;
    }
905331
public function getConflicts(array $files)
    {
        $conflicts = array();

        // flip so the files are hash keys to speed lookups
        $files = array_flip($files);

        $fileInfo = $this->getFileInfo();

        foreach ($files as $file => $garbage) {
            if (array_key_exists($file, $fileInfo)) {
                $fileFileInfo = $fileInfo[$file];
                if (isset($fileFileInfo['Conflicts'])
                    && is_array($fileFileInfo['Conflicts'])
                ) {
                    foreach ($fileFileInfo['Conflicts'] as $conflict) {
                        if (array_key_exists($conflict, $files)) {
                            if (!isset($conflicts[$file])) {
                                $conflicts[$file] = array();
                            }
                            $conflicts[$file][] = $conflict;
                        }
                    }
                }
            }
        }

        return $conflicts;
    }
5575
protected function extract(array $files)
    {
        foreach ($files as $key => $file) {
            if ($file instanceof Doozr_Request_File) {

                // Simple security layer
                $filename = $this->cleanFilename($file->getClientFilename());

                // @todo Move to a basic validation applied always for files if enabled in configuration.
                #$mediaType = $this->getMimeTypeByExtension(pathinfo($filename)['extension']);

                /* @var Doozr_Request_File $file */
                // Put everything in a simple array structure ...
                $files[$key] = [
                    'name'     => $filename,
                    'type'     => $file->getClientMediaType(),
                    'tmp_name' => $file->getTemporaryName(),
                    'error'    => $file->getError(),
                    'size'     => $file->getSize(),
                    'emulated' => false,
                ];
            } else {
                $files[$key] = $this->extract($file);
            }
        }

        return $files;
    }
1362544
protected function prepareFiles(array $files)
    {
        $prepared = array();
        foreach ($files as $file) {

            $type = $file->getType();
            $path = $file->getRealPath();
            $relative_path = gplcart_file_relative($path);

            $item = array(
                'info' => $file,
                'type' => $type,
                'path' => $relative_path,
                'owner' => fileowner($path),
                'extension' => $file->getExtension(),
                'size' => gplcart_file_size($file->getSize()),
                'command' => $type === 'dir' ? 'list' : 'read',
                'commands' => $this->command->getAllowed($file),
                'permissions' => gplcart_file_perms($file->getPerms())
            );

            $prepared[$relative_path] = $item;
            $prepared[$relative_path]['icon'] = $this->renderIcon($item);
        }

        return $prepared;
    }
819606
public function concat(array $files)
    {
        $baseUrl = trim($this->baseUrl, '/');
        $url = $this->concatUrl . '?f=' . implode(',', $files);
        return $baseUrl ? $url . '&b=' . trim($this->baseUrl, '/') : $url;
    }
1179985
public function requireFiles(array $files)
    {
        $path = $this->getPath();
        foreach ($files as $file) {
            $this->laravel['files']->requireOnce($path . '/' . $file . '.php');
        }
    }
446163
protected function filter_files( $files ) {
		if ( ! $files ) {
			return null;
		}

		foreach ( $files as $key => $file ) {
			if ( is_array( $file ) ) {
				$files[ $key ] = $this->filter_files( $files[ $key ] );
			}

			if ( empty( $files[ $key ] ) ) {
				unset( $files[ $key ] );
			}
		}

		return $files;
	}
1232244
private function hydrateAll(array $files)
    {
        foreach ($files as $name => $file) {
            // Recursive protection
            if (!is_array($file)) {
                continue;
            }

            foreach ($file as $key => $value) {
                if (is_array($value)) {
                    // Recursive call
                    $files[$name] = call_user_func(array($this, __FUNCTION__), $files[$name]);
                } else {
                    $files[$name] = $this->hydrate($file);
                }
            }
        }

        return $files;
    }
374756
private static function convertFilesArray($files) {
		
		$result = [];

		foreach($files as $field => $data) {
			
			foreach($data as $key => $val) {
				
				$result[$field] = [];
				
				if(false === is_array($val)) {
					$result[$field] = $data;
				} 
				else {
					
					$res = [];
					static :: filesFlip($res, [], $data);
					$result[$field] += $res;
				}
			}
		}

		return $result;
	}
988800
protected function normalizeFiles($files)
    {
        foreach ($files as $name => $info) {
            $this->loadFilesRecursive($name, $info['name'], $info['tmp_name'], $info['type'], $info['size'], $info['error']);
        }

        return $this->_files;
    }
1730
public static function createFromFilesGlobal(array $files) : array
    {
        $items = [];
        $files = self::normalizeSuperglobal($files);
        self::buildMap($files, $items);

        return $items;
    }
1041069
public function createUploadedFilesFromArray(array $files)
    {
        $uploadedFiles = [];

        if (isset($files['tmp_name']) && ! is_array($files['tmp_name'])) {
            $uploadedFiles[] = $this->createUploadedFile(
                $files['tmp_name'],
                $files['size'],
                $files['error'],
                $files['name'],
                $files['type']
            );
        } elseif (isset($files['tmp_name']) && is_array($files['tmp_name'])) {
            foreach ($files['tmp_name'] as $key => $file) {
                $uploadedFiles[] = $this->createUploadedFile(
                    $file,
                    $files['size'][$key],
                    $files['error'][$key],
                    $files['name'][$key],
                    $files['type'][$key]
                );
            }
        } else {
            foreach ($files as $key => $value) {
                $uploadedFiles[$key] = $this->createUploadedFilesFromArray($value);
            }
        }

        return $uploadedFiles;
    }
343779
public static function capture($files = null)
    {
        $files = $files ?? $_FILES;
        if (!is_array($files)) {
            return null;
        }

        $keys = array_keys($files);
        sort($keys);
        $multi = $keys !== ['error', 'name', 'size', 'tmp_name', 'type'];
        if (!$multi && is_array($files['name'])) {
            $multi = true;
            $files = array_map(function ($index) use ($files) {
                return array_combine(array_keys($files), array_column($files, $index));
            }, array_keys($files['name']));
        }

        if ($multi) {
            return array_filter(array_map([static::class, 'capture'], $files));
        }

        return new static($files['tmp_name'], $files['name'], $files['type'], $files['error']);
    }