我有一个这样的数组:
$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)
有没有解决方案?
答案 0 :(得分:5)
使用implode
-
"SELECT column_name(s)
FROM table_name
WHERE column_name IN (" .implode(',', $matches[0]) . ")";