1.源码:
public function importexcel(Request $request){
$file = Input::file('myfile');
if($file->isValid()){
$tmpName = $file->getClientOriginalName();
$path = $file->move(storage_path().'/uploads',$tmpName);
$subtmpName = substr($tmpName,0,-5);
$filePath = "storage/uploads/".iconv('UTF-8', 'UTF-8', $subtmpName).'.xlsx';
Excel::load($filePath, function($reader) {
$reader->noHeading();
$data = $reader->toArray();
for($i = 1;$i
2.问题:在函数体内变量$result(斜体)如何在方法体外部被调用即代码dd($result)处?
解决:参考:
var1 = 'from func1';
}
public function func2(){
echo $this->var1;
}
}
$demo = new demo();
$demo->func1();
$demo->func2();
在类定义变量,可以解决。有一点不好就是能让类内的所有方法都能访问到。我是希望变量只存在方法importexcel()体内,在 Excel::load($filePath, function($reader) {}变量$return,可以在外Excel::load()被访问到。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
$result = Excel::load($filePath, function($reader) {
return $result ,在外部直接使用访问importexcel这个类,由于你这个$result的结果由importexcel函数逻辑生成,不建议直接访问