json_encode(). Bind flags once (e.g. JSON_PRETTY_PRINT) for consistent output.
Creates a Closure that JSON-encodes an array or iterable with pre-bound flags and depth.
/**
* @param int $flags json_encode flags.
* @param int $depth Nodes deep to encode.
* @return Closure(mixed):?string
*/
Arrays\toJson(int $flags = 0, int $depth = 512): ClosureWhen Arrays\toJson() is called, it returns the following Closure which can be used like a regular function.
/**
* @param mixed $value
* @return string|null
*/
$function ($value): ?stringThis can be used to create a simple closure which can be used as a regular function.
$pretty = Arrays\toJson(JSON_PRETTY_PRINT);
echo $pretty(['name' => 'Ada', 'age' => 42]);
/*
{
"name": "Ada",
"age": 42
}
*/