-1

I have an array like this:

$str = 'In My Cart : 11 12 items';
preg_match_all('!\d+!', $str, $matches);
print_r($matches); // output is two number: 11, 12

Now I want to know, how can I pass this array $matches to this query?

SELECT column_name(s)
FROM table_name
WHERE column_name IN ($matches); // actually I want something like this: IN (11, 12)

Is there any solution?

Shafizadeh
  • 9,960
  • 12
  • 52
  • 89

1 Answers1

5

Use implode -

"SELECT column_name(s)
FROM table_name
WHERE column_name IN (" .implode(',', $matches[0]) . ")";
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87