Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

strpos function for arrays

Here is a function that checks if any of array values is a substring of a specified string. It takes string as haystack and array of needles and returns false if none of needles appeared in haystack or key of array of first needle that appeared in string:

<?php

function strpos_arr($haystack, $arr_needle){
    $valid = false;
    foreach($arr_needle as $key => $needle)
    {
        if(stripos($haystack, $needle) !== false)
        {
            $valid = $key;
            break;
        }
    }
    return $valid;
}
?>

You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus