Creating comma-separated '?' placeholders for SQL query parameters I have come up with a code that takes the total number of an array and creates ? for each, then separates them by a comma; leaving me a list like the one below:

?, ?, ?, ?, ?...


I am using this for my sql queries with prepared statements, instead of having to create the prepared statement each time, I want to just have an easily accessible class that does the heavy work.

So far I have a for loop code which I came up with to get the comma-separated question marks. First I create an array of [0] =&gt; ? ... based on the total number of the original array and then implode the value and add the comma between each element.

&lt;?php
$arr = array(
    'name' =&gt; 'James Bond',
    'age' =&gt; 60,
    'hobbies' =&gt; 'Saving England',
    'country' =&gt; 'England',
    'language' =&gt; 'English',
    'children' =&gt; 'too many to count'
);

for($i = 0; $i &lt; count($arr); $i++)
{
    $question[$i] = '?';
}    
print_r( implode(', ', $question) );
// outputs: ?, ?, ?, ?, ?, ?
?&gt;


Now my question is, is there a more efficient way of achieving this, such as a one-liner that just takes the total array number and creates the number automatically?
The ? array can be filled using array_fill:

implode(', ', array_fill(0, sizeof($arr), '?'))