1<?php
2$ids = array(1, 2, 3, 7, 8, 9);
3$inQuery = implode(',', array_fill(0, count($ids), '?'));
4
5$db = new PDO(...);
6$stmt = $db->prepare(
7 'SELECT *
8 FROM table
9 WHERE id IN(' . $inQuery . ')'
10);
11
12// bindvalue is 1-indexed, so $k+1
13foreach ($ids as $k => $id)
14 $stmt->bindValue(($k+1), $id);
15
16$stmt->execute();
17?>
18