<?php
$myArray = ['yellow', 'green', 'red'];
$myString = 'banana is ?, apple is ?, tomato is ?';
do {
$myString = preg_replace(
'/\?/',
array_shift($myArray),
$myString,
1,
$count
);
} while ($count && $myArray);
echo $myString;
echo "\n\n";
var_export($myArray);
- Output for 8.1.32, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- banana is yellow, apple is green, tomato is red
array (
)
preferences:
50.99 ms | 406 KiB | 5 Q