Well, it should theoretically be easy enough to modify it (the second version) to do that. However, in PHP we end up with something like:
Code:
function substr_in_array($needle, $haystack) {
if (!is_array($needle))
$needle = array($needle);
$haystack = addslashes(serialize($haystack));
return array_any($needle, create_function('$a',
"return array_any(unserialize('$haystack'), create_function('\$b',
\"return strpos(\\\$b, \$a) !== false;\"
));"
));
}
... so I think we're just going to stick with for loops...
Code:
function substr_in_array($needle, $haystack) {
if (!is_array($needle))
$needle = array($needle);
foreach ($needle as $a)
foreach ($haystack as $b)
if (strpos($b, $a) !== false)
return true;
return false;
}
The nice folks in ##php assure me that soon we'll be able to do:
Code:
function substr_in_array($needle, $haystack) {
if (!is_array($needle))
$needle = array($needle);
return array_any($needle, function($a) using ($haystack) {
return array_any($haystack, function($b) using ($a) {
return strpos($b, $a) !== false;
});
});
}
This is still a far cry from the Haskell substr_in_array needle haystack = any (any (`isInfixOf` haystack)) needle but beggars can't be choosers, eh?
Bookmarks