I was reading through the code and came across this syntax:
$customerIDs = array_map(function(Customer $customer) { return $customer->id; }, $customers);
where $customers is the array.
My confusion is in trying to understand function(Customer $customer). I see that Customer is a class, but what is $customer then?
This part:
is an anonymous function. It’s a "new" feature in PHP 5.3. It’s pretty much equivalent to:
As for the
Customer $customerpart, that’s just a type-constrained argument. It throws an error if the argument passed is not of typeCustomer.You can read more about anonymous functions at the php.net documentation.