gpt4 book ai didi

php - mySQL WHERE IN 与数组

转载 作者:行者123 更新时间:2023-11-29 08:58:19 25 4
gpt4 key购买 nike

我有一维数组 $abc。

$abc = array (90, 91, 92, 93, 94, 95, 96, 97, 98, 99);

我想在 WHERE IN 中使用它

SELECT *
FROM table
WHERE columnA IN ()

while (){
$def[] = $row['def'];
}

当我使用简单的 IN('$abc') 时,我有一个响应 - undefined variable :def

如何正确地做到这一点?

最佳答案

您可以使用implode()函数:

$abc = array (90, 91, 92, 93, 94, 95, 96, 97, 98, 99);
$str = implode(',', $abc);

现在您可以在 IN 子句中使用 $str

<小时/>

详细了解implode()功能。

关于php - mySQL WHERE IN 与数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9327164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com