I've the following code of lines in my application.
Can anybody please tell me what is the purpose of use
keyword in the following array_map()
function?
array_map( function($record) use ($edit_form, $otherfields, $otherfields_keys)
{
User::parseData($record, $edit_form['metadata']);
if (isset($otherfields[$record['user_id']])) {
return $record + $otherfields[$record['user_id']];
}
return $record + $otherfields_keys;
}, $records);
Thanks in advance.
The callback passed to array_map()
doesn't have access to outside variables so they must be passed using use
.
You can read more about anonymous functions in the PHP documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With