Home  >  Article  >  Backend Development  >  laravel 下函数内访问函数外变量

laravel 下函数内访问函数外变量

WBOY
WBOYOriginal
2016-06-06 20:37:021117browse

<code>    function something($p)
    {
        Mail::send('view', array(
            "email" => $p->email
        ), function ( $message) 
        {
            $message->to($p->email, $p->name)->subject('hello');
        })
    }
</code>

怎么在laravel框架下Mail::send的第三个参数闭包内访问闭包外的变量?

回复内容:

<code>    function something($p)
    {
        Mail::send('view', array(
            "email" => $p->email
        ), function ( $message) 
        {
            $message->to($p->email, $p->name)->subject('hello');
        })
    }
</code>

怎么在laravel框架下Mail::send的第三个参数闭包内访问闭包外的变量?

function () use ($var) {

http://php.net/manual/en/functions.anonymous.php#example-186

如何在 Laravel 中使用 SMTP 发送邮件(适用于 163、QQ、Gmail 等)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn