- str_repeat: documentation ( source)
<?php
$keywords = ['a', 'b'];
$temp = str_repeat('?, ', count($keywords) - 1) . '?';
echo $temp . "\n";
$keywords = ['a', 'b', 'c', 'd', 'e'];
$temp = str_repeat('?, ', count($keywords) - 1) . '?';
echo $temp . "\n";