PHP 在 array_map() 函数中使用关键字的目的?

Purpose of PHP use keyword in array_map() function?

我的应用程序中有以下几行代码。 谁能告诉我以下 array_map() 函数中 use 关键字的用途是什么?

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);

提前致谢。

传递给 array_map() 的回调无法访问外部变量,因此必须使用 use 传递它们。

您可以在 PHP documentation 阅读更多关于匿名函数的信息。