This is not as straightforward as it could be, because str_replace is a global replace - the first call will replace all xxxs with the replacement value. You can use preg_replace, and call it multiple times with $limit=1.
$my_string = "RGB colors are xxx, xxx, xxx";
$my_array = [ "red", "green", "blue" ];
$placeholder = '/xxx/';
foreach ($my_array as $color) {
$my_string = preg_replace($placeholder, $color, $my_string, 1);
}
Note that that modifies the original string; you should make a copy and use that instead of $my_string inside the loop if you don't want that to happen.
You could also use sprintf as suggested in the comments, with a little preparation:
$args = $my_array;
array_unshift($args, str_replace(['%','xxx'], ['%%','%s'], $my_string));
$result = call_user_func_array(sprintf, $args);
"xxx"? Can you change them? If so, try usingsprintf()(possibly withcall_user_func_array).