null if the property is missing.
Creates a Closure that reads a named property/index from any array or object. Works transparently across both — `['name' => 'Ada']` and `(object)['name' => 'Ada']` both yield 'Ada'.
/**
* @param string $property
* @return Closure(mixed):mixed
*/
GeneralFunctions\getProperty(string $property): ClosureWhen GeneralFunctions\getProperty() is called, it returns the following Closure which can be used like a regular function.
/**
* @param array|object $record
* @return mixed
*/
$function ($record)This can be used to create a simple closure which can be used as a regular function.
$getName = GeneralFunctions\getProperty('name');
echo $getName(['name' => 'Ada']); // 'Ada'
echo $getName((object) ['name' => 'Bea']); // 'Bea'
// As a callback:
$names = array_map($getName, [
['name' => 'Ada'],
['name' => 'Bea'],
]);
print_r($names); // ['Ada', 'Bea']