public function convertToString($input, $separator = ' '): string
    {
        $separator = (string)$separator;
        $string = is_array($input) ? implode($separator, $input) : (string)$input;

        // Remove double space and trim the string
        return trim(preg_replace('/(\s)+/', ' ', $string));
    }
public function convertToString($input, $separator = ' '): string
    {
        $separator = (string)$separator;
        $string = is_array($input) ? implode($separator, $input) : (string)$input;

        // Remove double space and trim the string
        return trim(preg_replace('/(\s)+/', ' ', $string));
    }
public function convertToString ( $ input , $ separator = ' ' ) : string { $ separator = ( string ) $ separator ; $ string = is_array ( $ input ) ? implode ( $ separator , $ input ) : ( string ) $ input ; // Remove double space and trim the string return trim ( preg_replace ( '/(\s)+/' , ' ' , $ string ) ) ; }
Helper to make sure we got a string back

Examples:

Carbon.String.convertToString(' helloworld  ') == 'helloworld'
Carbon.String.convertToString([' hello', ' world']) == 'hello world'
Carbon.String.convertToString(['hello', 'world'], '-') == 'hello-world'

@param string|array $input     A string or an array
@param string       $separator The $separator

@return string The converted string
Helper to make sure we got a string back