Php 如何将数组传递到IN()子句中?
我有这样一个数组:Php 如何将数组传递到IN()子句中?,php,mysql,arrays,Php,Mysql,Arrays,我有这样一个数组: $str = 'In My Cart : 11 12 items'; preg_match_all('!\d+!', $str, $matches); print_r($matches); // output is two number: 11, 12 现在我想知道,如何将数组$matches传递给这个查询 SELECT column_name(s) FROM table_name WHERE column_name IN ($matches); // actually I
$str = 'In My Cart : 11 12 items';
preg_match_all('!\d+!', $str, $matches);
print_r($matches); // output is two number: 11, 12
现在我想知道,如何将数组$matches传递给这个查询
SELECT column_name(s)
FROM table_name
WHERE column_name IN ($matches); // actually I want something like this: IN (11, 12)
有什么解决办法吗?使用内爆-
似乎正确,谢谢。。。我会检查它,并接受它作为我的答案,如果工作正确+1 upvoteWell,有一个小问题,这个内爆的输出“,”,$matches是这样的:数组!我想我需要两个匹配项你能添加var_dump$匹配项吗?array1{[0]=>array2{[0]=>string2 11[1]=>string2 12}检查更新的答案。
"SELECT column_name(s)
FROM table_name
WHERE column_name IN (" .implode(',', $matches[0]) . ")";