Creates a function which casts an array to a string using the defined glue.
/**
* Returns a Closure for casting an array to a string.
*
* @param string|null $glue
* @return Closure(array<int|string, mixed>): string
*/
Arrays\toString(?string $glue): ClosureWhen Arrays\toString() is called, it returns the following Closure which can be used like a regular function.
/**
* @param array<int|string, mixed> $array
* @return string
*/
$function (array $data): stringThis can be used to create a simple closure which can be used as a regular function.
// Create the closure that casts an array to a string with a comma as the glue.
$commaSeparated = Arrays\toString(',');
// Called as a function.
var_dump($commaSeparated(['b', 'c'])); // b,cThis can be called inline using currying.
// Casts to a string with - as the glue
print Arrays\toString('-')(['b', 'c']); // b-cIf 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( Arrays\toString('---'), [
['Once', 'upon', 'time'],
['Find', 'the', 'time']
]);
print_r($array); // ['Once---upon---time', 'Find---the---time']