rtrim().
Allows you to create a function which can be used to trim any matches from a mask. Trims the matching values from the end only These can either be used as part of a Higher Order Function such as array_map() or as part of a compiled/pipe function.
/**
* @param string $mask
* @return Closure(string):string
*/
Strings\rTrim(string $mask = "\t\n\r\0\x0B"): ClosureWhen Strings\rTrim() is called, it returns the following Closure which can be used like a regular function.
/**
* @param string $string The string to be trimmed
* @return string
* @psalm-pure
*/
$function(string $string): stringRelated Functions
This can be used to create a simple closure which can be used as a regular function.
// Create a closure which will get all instances of IT in a string.
$trimStar = Strings\rTrim('*');
// Called as a function.
echo $trimStar('*This is a string, with it in it*'); // *This is a string, with it in it
// Used in a higher order function.
$array = array_map( $trimStar, ['**Hi*****', '***Bye*']);
print_r($array); // ['**Hi', '***Bye']This can be called inline using currying.
echo Strings\rTrim('_')('___This is a string, with it in it___'); // ___This is a string, with it in itIf you are not planning on reusing the Closure created, you can just call it inline with a higher order function as its callable.
$array = array_map(Strings\rTrim('-'), ['--Hi-', '-Bye--']);
print_r($array); // ['--Hi', '-Bye']