I need to replace multiple instances of a certain string (question mark) with strings from an array. e.g. if the string I wish to replace appears 3 times and my array has a length of 3, the first one would be replaced by the first item in the array, the second by the second etc etc.
You may recongise it's quite similar to the way prepared statements work in mysqli.
Here's an example:
$myArray = array( [0] => 'yellow', [1] => 'green', [2] => 'red' ); $myString = 'banana is ?, apple is ?, tomato is ?'; $newString = someFunction($myString,$myArray); echo $newString;
This would then return
banana is yellow, apple is green, tomato is red
Can anyone suggest a way of doing this using PHP 5.2.