我正在寻找一种与in_array相同的替代函数,但它也可以检查搜索项是否仅包含给定元素的一部分而不是整个元素:PHP如何检查数组是否包含另一个数组的模式
目前与下面的脚本工作:
$attributes = array('dogs', 'cats', 'fish');
if (in_array($attributes, array('dog','cats','fishess'), true)) {
* does something for cats, but not for dogs and fish
because the function only checks if the given term is identical to the word in the array instead of only a part of the word *
}
我将如何建立我起来的功能,使其通过的话只包含在阵列藏汉文字的部分?
首选的例子是这个样子:
$words = array('fish', 'sharks');
if (*word or sentence part is* in_array($words, array('fishing', 'sharkskin')){
return 'your result matched 2 elements in the array $words
}
http://php.net/manual/en/function.array-intersect.php – mkaatman
更妙的是HTTP:// PHP。 net/manual/en/function.array-uintersect.php – dan08
这类问题的一个重要细节是针阵列的大小和干草堆阵列的大小是多少。根据这些尺寸,如果性能很重要,答案可能完全不同。 –