gpt4 book ai didi

php - 试图访问 laravel 集合之外的变量-> 每个

转载 作者:可可西里 更新时间:2023-11-01 00:18:32 24 4
gpt4 key购买 nike

我正在尝试访问 laravel 集合之外的变量->每个,但我得到 ..

Undefined variable: headers

这是我的代码:

public function bulkCoding(Request $request) {

Excel::load($request->file, function($reader) {
$headers = $reader->get()->first()->keys();

// Loop through all sheets
$reader->each(function($sheet) {
$headers->each(function ($title) {
dd($title);
});
});
});

}

最佳答案

您需要使用use()pass variable inside the closure scope :

each(function($sheet) use($headers) {

关于php - 试图访问 laravel 集合之外的变量-> 每个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48367053/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com