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?
Edit: I am already using prepared statements which achieves the above. I am looking for a way to get the raw query back to show as part of debug output.