php - 如何将变量传递给匿名函数?
问题描述
为什么 Laravel 说电子邮件不是一个已定义的变量???
$title = 'hi';
$content = 'hi';
$email='topher@site.com';
Mail::send('confirmation', ['title' => $title, 'content' => $content], function ($message) {
$message->from('john@site.com', 'Topher');
$message->to($email);
});
解决方案
你在一个函数中使用它,那是一个不同的范围。use($email)
在您的函数参数之后添加。
function($message) use($email)
推荐阅读
- google-chrome - 自动导出 Fetch/XHR 响应 Chrome
- visual-studio-code - 为什么我的python文件可以在pycharm上访问的东西不能在vscode中使用?
- ffmpeg - 为什么 -force_key_frames 添加 VOP start_codes?(ffmpeg)
- javascript - 从嵌套函数访问嵌套变量
- spring - 弹簧块大小是否影响数据库插入
- css - 带有动画延迟中断的 SVG / CSS 动画
- swift - 并发世界中的 SwiftUI macOS 文档应用架构
- python - 外键中的 Django 过滤模型
- c++ - 当方法可用时如何专门化模板?
- sql - 两个查询的 Hive 联合给出编译错误