3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myArray = ['yellow', 'green']; $myString = 'banana is ?, apple is ?, lemon is ?, tomato is ?'; $count = count($myArray); $i = 0; while (($pos = strpos($myString, '?')) !== false) { $myString = substr_replace( $myString, $myArray[$i++ % $count], $pos, 1 ); } echo $myString;

preferences:
29.54 ms | 405 KiB | 5 Q