I have an array with multiple values called $my_replacements.
I have a string called $my_string.
I want to be able to iterate over $my_replacements and perform a preg_replace on $my_string, so right now I have this:
foreach($my_replacements as $replacement) {
preg_replace($replacement, '', $my_string);
}
This works fine, but I would just like the loop to stop when a replacement is done to $my_string, and when that happens I want to get the value of this new $my_string with the value replaced out of it.
How would I do that?
You need to compare the result with the string before replacing something:
From the docs:
If this is not the case, we break, i.e. exit the loop.