3v4l.org

run code in 300+ PHP versions simultaneously
<?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;

preferences:
23.02 ms | 405 KiB | 5 Q