I am reading this answer: PHP - Using PDO with IN clause array
It uses the code:
$in_array = array(1, 2, 3);
$in = str_repeat('?,', count($in_array) - 1) . '?';
$sql = "SELECT * FROM my_table WHERE my_value IN ($in)";
$stm = $db->prepare($sql);
$stm->execute($in_array);
$data = $stm->fetchAll();
Can anyone explain why they used
$in = str_repeat('?,', count($in_array) - 1) . '?';
instead off:
$in = str_repeat('?,', count($in_array));
I am puzzled and cannot figure out the logic behind the trailing - 1) . '?'