src/Manipulator.php
public function eachWord(\Closure $closure, bool $preserveSpaces = false) : Manipulator
    {
        $modifiedString = '';

        foreach (explode(' ', $this->string) as $word) {
            $modifiedString .= $closure($word);
            $modifiedString .= $preserveSpaces ? ' ' : '';
        }

        return new static(trim($modifiedString));
    }
public function eachWord(\Closure $closure, bool $preserveSpaces = false) : Manipulator
    {
        $modifiedString = '';

        foreach (explode(' ', $this->string) as $word) {
            $modifiedString .= $closure($word);
            $modifiedString .= $preserveSpaces ? ' ' : '';
        }

        return new static(trim($modifiedString));
    }
public function eachWord ( \ Closure $ closure , bool $ preserveSpaces = false ) : Manipulator { $ modifiedString = '' ; foreach ( explode ( ' ' , $ this -> string ) as $ word ) { $ modifiedString .= $ closure ( $ word ) ; $ modifiedString .= $ preserveSpaces ? ' ' : '' ; } return new static ( trim ( $ modifiedString ) ) ; }
Perform an action on each word in the string.

@param $closure
@param bool $preserveSpaces
@return object|Manipulator
Perform an action on each word in the string .