3v4l.org

run code in 300+ PHP versions simultaneously
<?php $notes = array( '-Rnote', '-Gnote', '-Ynote', 'note1 -R', '-Gnote1', '-Ynote1', ); $colors = array( '-R' => 'red', '-G' => 'green', '-Y' => 'yellow', ); foreach ($notes as $note ) { If(isset($colors[substr($note,0,2)])){ echo str_replace(substr($note, 0, 2), '<span style="background-color:' . $colors[substr($note, 0, 2)] . '">', $note) . "</span>\n"; }Else{ Echo $note ."\n"; } }

preferences:
39.77 ms | 405 KiB | 5 Q