public static function slash(string ...$sections)
    {
        $count = count($sections);

        // If we only got a single section, return it.
        if (1 === $count) {
            return $sections[0];
        } // Somehow we got NO sections, so return null.
        elseif (0 >= $count || empty($sections)) {
            return null;
        } // Only two sections; concatenated and return!
        elseif (2 === $count) {
            $compiled = sprintf(
                "%s%s%s",
                trim($sections[0]),
                DIRECTORY_SEPARATOR,
                trim($sections[1])
            );
            // Check for double-slashes
            return preg_replace(
                '/\\\\{2,}|\/{2,}/',
                DIRECTORY_SEPARATOR,
                $compiled
            );
        } // Multiple sections, so let's get recursive!
        else {
            $append = array_shift($sections);
            $prepend = array_shift($sections);
            $compiled = static::slash($append, $prepend);

            return static::slashAr(array_merge([$compiled], $sections));
        }
    }
public static function slash(string ...$sections)
    {
        $count = count($sections);

        // If we only got a single section, return it.
        if (1 === $count) {
            return $sections[0];
        } // Somehow we got NO sections, so return null.
        elseif (0 >= $count || empty($sections)) {
            return null;
        } // Only two sections; concatenated and return!
        elseif (2 === $count) {
            $compiled = sprintf(
                "%s%s%s",
                trim($sections[0]),
                DIRECTORY_SEPARATOR,
                trim($sections[1])
            );
            // Check for double-slashes
            return preg_replace(
                '/\\\\{2,}|\/{2,}/',
                DIRECTORY_SEPARATOR,
                $compiled
            );
        } // Multiple sections, so let's get recursive!
        else {
            $append = array_shift($sections);
            $prepend = array_shift($sections);
            $compiled = static::slash($append, $prepend);

            return static::slashAr(array_merge([$compiled], $sections));
        }
    }
public static function slash ( string ... $ sections ) { $ count = count ( $ sections ) ; // If we only got a single section, return it. if ( 1 === $ count ) { return $ sections [ 0 ] ; } // Somehow we got NO sections, so return null. elseif ( 0 >= $ count || empty ( $ sections ) ) { return null ; } // Only two sections; concatenated and return! elseif ( 2 === $ count ) { $ compiled = sprintf ( "%s%s%s" , trim ( $ sections [ 0 ] ) , DIRECTORY_SEPARATOR , trim ( $ sections [ 1 ] ) ) ; // Check for double-slashes return preg_replace ( '/\\\\{2,}|\/{2,}/' , DIRECTORY_SEPARATOR , $ compiled ) ; } // Multiple sections, so let's get recursive! else { $ append = array_shift ( $ sections ) ; $ prepend = array_shift ( $ sections ) ; $ compiled = static :: slash ( $ append , $ prepend ) ; return static :: slashAr ( array_merge ( [ $ compiled ] , $ sections ) ) ; } }
Combine strings with a directory separator.

Accepts any number of strings.

This is purely string manipulation: Although this function will likely
be used for paths, it does no path validation of any sort.

@param string[] ...$sections All strings you wish to concatenate.
@return string
Combine strings with a directory separator .