Creates a Closure that writes a value into a named property/index on a record. Works with both arrays and objects.
/**
* @param array<string,mixed>|ArrayObject<string,mixed>|object $store
* @param string $property
* @return Closure(mixed):(array<string,mixed>|ArrayObject<string,mixed>|object)
*/
GeneralFunctions\setProperty($store, string $property): ClosureWhen GeneralFunctions\setProperty() is called, it returns the following Closure which can be used like a regular function.
/**
* @param mixed $value
* @return array|object
*/
$function ($value)This can be used to create a simple closure which can be used as a regular function.
$user = (object) ['name' => 'Ada', 'role' => 'user'];
$setRole = GeneralFunctions\setProperty($user, 'role');
$promoted = $setRole('admin');
echo $promoted->role; // 'admin'