Replace repeating character with array elements in PHP
- by Will Croft
I hope this is blindingly obvious: I'm looking for the fastest way to replace a repeating element in a string with the elements in a given array, e.g. for SQL queries and parameter replacement.
$query = "SELECT * FROM a WHERE b = ? AND c = ?";
$params = array('bee', 'see');
Here I would like to replace the instances of ? with the corresponding ordered array elements, as so:
SELECT * FROM a WHERE b = 'bee' and c = 'see'
I see that this might be done using preg_replace_callback, but is this the fastest way or am I missing something obvious?