I've been looking for a way to check if any of an array of values exists in a string, but it seems that PHP has no native way of doing this, so I've come up with the below.
My question - is there a better way of doing this, as this seems pretty inefficient? Thanks.
$match_found = false;
$referer = wp_get_referer();
$valid_referers = array(
'dd-options',
'dd-options-footer',
'dd-options-offices'
);
/** Loop through all referers looking for a match */
foreach($valid_referers as $string) :
$referer_valid = strstr($referer, $string);
if($referer_valid !== false) :
$match_found = true;
continue;
endif;
endforeach;
/** If there were no matches, exit the function */
if(!$match_found) :
return false;
endif;
$referervariable ?continue;does not make much sense, as there is no more code inside the loop which could be skipped. If you only want to know if there is at least one match, usebreak;instead. This way the loop will stop at the first match.breakonce you have found the first matching referer (and not tocontinue). Edit: beaten by Yoshi :)break;after an earlier attempt!