- strpos: documentation ( source)
- substr_replace: documentation ( source)
<?php
$myArray = ['yellow', 'green', 'red'];
$myString = 'banana is ?, apple is ?, tomato is ?';
$i = 0;
while (($pos = strpos($myString, '?')) !== false) {
$myString = substr_replace(
$myString,
$myArray[$i++],
$pos,
1
);
}
echo $myString;