Skip to content
Advertisement

Using an array as needles in strpos

How do you use the strpos for an array of needles when searching a string? For example:

JavaScript

Because when using this, it wouldn’t work, it would be good if there was something like this

Advertisement

Answer

@Dave an updated snippet from http://www.php.net/manual/en/function.strpos.php#107351

JavaScript

How to use:

JavaScript

will return true, because of array "cheese".

Update: Improved code with stop when the first of the needles is found:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement