当我执行foreach()
循环时,当前数组元素的值$recipient
未在行->to($recipient)
上定义。为什么是这样?foreach循环中的未定义变量
PHP代码(抛出错误)
foreach($recipients as $recipient) {
Mail::send('emails.invite', $data, function($m){
$m
->from('[email protected]', Auth::user()->name)
->to($recipient)
->subject('Auth::user()->name has invited you!');
});
}
错误
Notice: Undefined variable: recipient
PHP代码(没有错误)
foreach($recipients as $recipient) {
echo $recipient;
}
作品,谢谢!! – Nyxynyx 2013-03-25 00:42:38
欢迎您!曾经有过这个问题。 PHP文档对此没有太多的说明。 – hek2mgl 2013-03-25 00:45:53