str_ends_with().
Returns a function which can be used to check if a string ends with a defined sub string. The created function can then reused over any string, or used as part of a Higher Order Function such as array_filter().
/**
* @param string $find The value to look for.
* @return Closure(string):bool
*/
Strings\endsWith(string $find): ClosureWhen Strings\endsWith() is called, it returns the following Closure which can be used like a regular function.
/**
* @param string $source
* @return bool
* @psalm-pure
*/
$function(string $source): boolThis can be used to create a simple closure which can be used as a regular function.
// Create function to check if a string starts with 'foo'
$endsWithFoo = Strings\endsWith('foo');
// Called as a function.
$endsWithFoo('ends foo'); // true
$endsWithFoo('foo not at end'); // false
// Used in a higher order function.
$array = array_filter(['ends foo', 'foo not at end'], $endsWithFoo);
print_r($array); // ['ends foo']This can be called inline using currying.
Strings\endsWith('foo')('ends foo'); // true
Strings\endsWith('foo')('foo not at end'); // falseIf 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_filter(['ends foo', 'foo not at end'], Strings\endsWith('foo'));
// ['ends foo']