Php 如何在laravel 4.2中用两个值检查一个字段
总是说未定义的变量:输入 将电子邮件与两个值进行比较的最佳方法是什么请指导添加Php 如何在laravel 4.2中用两个值检查一个字段,php,laravel,Php,Laravel,总是说未定义的变量:输入 将电子邮件与两个值进行比较的最佳方法是什么请指导添加使用($input)将$input变量传递到关闭范围: $input = Input::all(); $user = User::where(function($q) { $q->where('email', $input['email'] ) ->orWhere('email', $input['emails'][0]['value'] ); }
使用($input)
将$input
变量传递到关闭范围:
$input = Input::all();
$user = User::where(function($q) {
$q->where('email', $input['email'] )
->orWhere('email', $input['emails'][0]['value'] );
})
->first();
print_r($user);die;
闭包也可以从父范围继承变量。任何此类变量都必须传递给use
语言结构
但是请确保您始终具有此值$input['emails'][0]['value']为什么不打印($input);你需要在函数子句中添加
use
,上面写着未定义的索引:emailArray([kind]=>plus#person[etag]=>“s/s”[birth]=>1996-08-18[gender]=>male[emails]=>Array([0]=>数组([值]=>s@gmail.com[type]=>account]@AmanJoshi这是一个完全不同的错误。这意味着您现在可以访问闭包中的$input
变量,但该变量没有email
。请执行$input[emails][0][0]['value']
而不是$input['email']
有两个条件,我获取电子邮件和电子邮件数组需要设置bothYes@Alexey mezen,如果电子邮件未定义,它将跳过什么方式,如果存在,它将检查电子邮件数组。它可以是电子邮件变量或电子邮件数组,我想从输入值检查用户的电子邮件
User::where(function ($q) use ($input) {
User::where(function($q) use ($input) {
$q->where('email', $input['emails'][0]['value']);
if (array_key_exists('email', $input)) {
$q->orWhere('email', $input['emails'][0]['value']);
}
})