简体   繁体   中英

How can i use an array in a Where Clause in Laravel Query Builder?

I want to use the array $aqui inside where clause, but I don't know how to do it. I know how to put multiple values inside where clause, but I don't know about arrays .

$aqui[1] = 35;
$aqui[2] = 67;
$aqui[3] = 44;
$aqui[4] = 12;
$aqui[5] = 9;
//and goes...

$caraio = DB::connection('mysql')
->table('users')
->select('name')
->where( /* where fields are equal to $aqui */ )
->value('name');

Just use:

$aqui[1] = 35;
$aqui[2] = 67;
$aqui[3] = 44;
$aqui[4] = 12;
$aqui[5] = 9;
//and goes...

$caraio = DB::connection('mysql')
->table('users')
->select('name')
->whereIn('attributeName', $aqui)
->value('name');

Obviously you want to replace attributeName with the name of the attribute that you want to compare values against.

Read more about it here .

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM