Ok, I’m feeling retarded here,
I have a string like so:
$string = 'function module_testing() {';
or it could be like this:
$string = 'function module_testing()';
or it could be like this:
$string = 'function module_testing($params) {';
or this:
$string = 'function module_testing($params, $another = array())';
and many more ways…
And than I have an array of strings like so:
$string_array = array('module_testing', 'another_function', 'and_another_function');
Now, is there some sort of preg_match that I can do to test if any of the $string_array values are found within the $string string at any given position? So in this situation, there would be a match. Or is there a better way to do this?
I can’t use in_array since it’s not an exact match, and I’d rather not do a foreach loop on it if I can help it, since it’s already in a while loop.
Thanks 🙂
A
foreachloop here is the appropriate solution. Not only is it the most readable but you’re looping over three values. The fact that happens within awhileloop is a non-issue.You can alternatively use a regular expression:
There are two parts to this. Firstly, there is the
|syntax:which means find
a,borc. The second part is:which escapes the contents. This means if your search strings contain any regex special characters (eg
() then the regex will still work correctly.Ultimately though I can’t see this being faster than the
foreachloop.