I am trying to search for multiple strings within a larger string and if none of them are a match, manipulate the original string. Here is the code:
$searchthis = 'this is a string'
$arr = array('foo', 'bar');
foreach ($arr as &$value) {
if (strpos($searchthis, $value) !== false) {
break;
}
else{
$searchthis = $searchthis . ' addthis';
}
}
The problem is after searching the first string variable and not matching, the original searched string is manipulated before running the next test.
Any thoughts? Thanks in advance
You need to be checking to see if there was not a match outside of your loop. You can accomplish this by setting a variable (
$found) totruewhen there was at least one string found: