<?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;
- Output for 8.1.32, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.13
- banana is yellow, apple is green, tomato is red
preferences:
50.44 ms | 406 KiB | 5 Q