src/Utilities/Miscellaneous.php
public static function concatenatePaths($paths)
    {
        // If paths are not provided as array, get the paths from methods' arguments
        if (!is_array($paths)) {
            $paths = func_get_args();
        }

        // No paths provided?
        // Nothing to do
        if (empty($paths)) {
            return '';
        }

        $concatenated = '';
        $firstWindowsBased = false;
        $separator = DIRECTORY_SEPARATOR;

        foreach ($paths as $path) {
            $path = trim($path);

            // Empty paths are useless
            if (empty($path)) {
                continue;
            }

            // Does the first path is a Windows-based path?
            if (Arrays::isFirstElement($paths, $path)) {
                $firstWindowsBased = Regex::isWindowsBasedPath($path);

                if ($firstWindowsBased) {
                    $separator = '\\';
                }
            }

            // Remove the starting / beginning directory's separator
            $path = self::removeStartingDirectorySeparator($path, $separator);

            // Removes the ending directory's separator
            $path = self::removeEndingDirectorySeparator($path, $separator);

            /*
             * If OS is Windows, first part of the concatenated path should be the first passed path,
             * because in Windows paths starts with drive letter, e.g. "C:", and the directory separator is not
             * necessary at the beginning.
             */
            if ($firstWindowsBased && empty($concatenated)) {
                $concatenated = $path;

                continue;
            }

            // Concatenate the paths / strings with OS-related directory separator between them (slash or backslash)
            $concatenated = sprintf('%s%s%s', $concatenated, $separator, $path);
        }

        return $concatenated;
    }
public static function concatenatePaths($paths)
    {
        // If paths are not provided as array, get the paths from methods' arguments
        if (!is_array($paths)) {
            $paths = func_get_args();
        }

        // No paths provided?
        // Nothing to do
        if (empty($paths)) {
            return '';
        }

        $concatenated = '';
        $firstWindowsBased = false;
        $separator = DIRECTORY_SEPARATOR;

        foreach ($paths as $path) {
            $path = trim($path);

            // Empty paths are useless
            if (empty($path)) {
                continue;
            }

            // Does the first path is a Windows-based path?
            if (Arrays::isFirstElement($paths, $path)) {
                $firstWindowsBased = Regex::isWindowsBasedPath($path);

                if ($firstWindowsBased) {
                    $separator = '\\';
                }
            }

            // Remove the starting / beginning directory's separator
            $path = self::removeStartingDirectorySeparator($path, $separator);

            // Removes the ending directory's separator
            $path = self::removeEndingDirectorySeparator($path, $separator);

            /*
             * If OS is Windows, first part of the concatenated path should be the first passed path,
             * because in Windows paths starts with drive letter, e.g. "C:", and the directory separator is not
             * necessary at the beginning.
             */
            if ($firstWindowsBased && empty($concatenated)) {
                $concatenated = $path;

                continue;
            }

            // Concatenate the paths / strings with OS-related directory separator between them (slash or backslash)
            $concatenated = sprintf('%s%s%s', $concatenated, $separator, $path);
        }

        return $concatenated;
    }
public static function concatenatePaths ( $ paths ) { // If paths are not provided as array, get the paths from methods' arguments if ( ! is_array ( $ paths ) ) { $ paths = func_get_args ( ) ; } // No paths provided? // Nothing to do if ( empty ( $ paths ) ) { return '' ; } $ concatenated = '' ; $ firstWindowsBased = false ; $ separator = DIRECTORY_SEPARATOR ; foreach ( $ paths as $ path ) { $ path = trim ( $ path ) ; // Empty paths are useless if ( empty ( $ path ) ) { continue ; } // Does the first path is a Windows-based path? if ( Arrays :: isFirstElement ( $ paths , $ path ) ) { $ firstWindowsBased = Regex :: isWindowsBasedPath ( $ path ) ; if ( $ firstWindowsBased ) { $ separator = '\\' ; } } // Remove the starting / beginning directory's separator $ path = self :: removeStartingDirectorySeparator ( $ path , $ separator ) ; // Removes the ending directory's separator $ path = self :: removeEndingDirectorySeparator ( $ path , $ separator ) ; /*
             * If OS is Windows, first part of the concatenated path should be the first passed path,
             * because in Windows paths starts with drive letter, e.g. "C:", and the directory separator is not
             * necessary at the beginning.
             */ if ( $ firstWindowsBased && empty ( $ concatenated ) ) { $ concatenated = $ path ; continue ; } // Concatenate the paths / strings with OS-related directory separator between them (slash or backslash) $ concatenated = sprintf ( '%s%s%s' , $ concatenated , $ separator , $ path ) ; } return $ concatenated ; }
Returns concatenated given paths

The paths may be passed as:
- an array of paths / strings
- strings passed as following arguments

Examples:
- concatenatePaths(['path/first', 'path/second', 'path/third']);
- concatenatePaths('path/first', 'path/second', 'path/third');

@param array|string $paths Paths co concatenate. As described above: an array of paths / strings or strings
passed as following arguments.
@return string
Returns concatenated given paths