【问题标题】:why not use Function arguments in php laravel lazyCollection为什么不在 php laravellazyCollection 中使用函数参数
【发布时间】:2020-12-18 09:36:52
【问题描述】:

这是我的代码

public function createUsersNumberTest($number){
    $collect=LazyCollection::make(function($number){
        dd($number);
    }
    );
    $collect->collect();
}

为什么我不在函数中使用 $number?

【问题讨论】:

    标签: php laravel arguments


    【解决方案1】:

    由于您在其中有一个 anonymous 函数,因此您的 $number 无法通过 use 传递它

    public function createUsersNumberTest($number){
    $collect=LazyCollection::make(function() use ($number) {
        dd($number);
    }
    );
    $collect->collect();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-26
      • 2017-06-14
      • 1970-01-01
      • 2015-08-04
      • 2020-03-06
      • 2022-05-16
      相关资源
      最近更新 更多