Find string in (String or Array)

In this custom function, we will create small php function that will search string  in string or in array  in php.

/**
   * Determine if a given string contains a given substring.
   *
   * @param  string  $haystack
   * @param  string|array  $needles
   * @return bool
*/

function contains ( $haystack, $needles ) {

    foreach ((array) $needles as $needle) {
        if ($needle != '' && mb_strpos($haystack, $needle) !== false) {
            return true;
        }
    }

    return false;
}

 


Loading ...

Related Results :

  1. Find string in (String or Array)
Note :
  • Related Posts are generally User Blog posts.
  • or Other tutorials from other networks of w3clan.com.
  • Any registered user can create related posts based on search term tags.

About the Author