Creates a predicate Closure that is true when a given property/index exists on an array or object.
/**
* @param string $property
* @return Closure(mixed[]|object):bool
*/
GeneralFunctions\hasProperty(string $property): ClosureWhen GeneralFunctions\hasProperty() is called, it returns the following Closure which can be used like a regular function.
/**
* @param array|object $record
* @return bool
*/
$function ($record): boolThis can be used to create a simple closure which can be used as a regular function.
$hasEmail = GeneralFunctions\hasProperty('email');
$users = [
['name' => 'Ada', 'email' => 'a@x'],
['name' => 'Bea'],
];
$withEmail = array_filter($users, $hasEmail);
print_r($withEmail); // [['name' => 'Ada', 'email' => 'a@x']]