I have to say that I like the simplicity of the Gre_gor answer , but for a more dynamic method, you can also use array_filter():
function my_array_search($array, $needle){
$matches = array_filter($array, function ($haystack) use ($needle){
return strpos($needle, $haystack) !== false;
});
return empty($matches) ? false : $matches;
}
$namesArray = ['Peter', 'Glenn', 'Meg', 'Griffin'];
Examples:
if(my_array_search($namesArray, 'Glenn Quagmire')){
echo 'There is';
} else {
echo 'There is not';
}
if(($retval = my_array_search($namesArray, 'Peter Griffin'))){
echo 'There is';
print_r($retval);
} else {
echo 'There is not';
}
$retval , . , $matches my_array_search , false .