php - 如何在 Laravel 查询生成器的 Where 子句中使用数组?
问题描述
我想使用数组 $aqui
insidewhere
子句,但我不知道该怎么做。我知道如何在where
子句中放置多个值,但我不知道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');
解决方案
只需使用:
$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');
显然,您想替换attributeName
为要比较值的属性的名称。
在此处阅读更多相关信息。
希望这可以帮助!
推荐阅读
- excel - 复杂的查找和替换
- linux - Linux Bash 中的一行命令
- sql - 如何选择具有子字符串的行
- python-3.x - tensorflow api 2.0 张量对象仅在启用急切执行时才可迭代。要迭代此张量,请使用 tf.map_fn
- qt - QML滚动区域,列堆叠项目在彼此之上
- .net - 如何在 Catia 中循环遍历 catpart
- javascript - 当列是 JSON 数组而不是字符串时如何过滤 ANTD 表
- c# - .net 4.62 c# 参考总是指向 GAC,即使安装 nuget 包
- html - CSS:空白空间中图像div下的文本
- python - 如何修复'TypeError:'ArcGIS'类型的参数在geopy上不可迭代'错误?