To use an array in the WHERE
clause, IN ()
, you need to create as many "?"
as there are items in the array.
A simple foreach
or for
loop before the SELECT
clause will do.
In the loop, for each item in the array, you will add "?" to a string $numberOfItems
.
So, if there are 4 items in the array, the string will look like this:
?, ?, ?, ?
In place of WHERE
code IN (?)
, it will be WHERE
code IN ($numberOfItems)
,
which is equivalent to WHERE
code IN (?, ?, ?, ?)
.