我正在尋找一種與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
這類問題的一個重要細節是針陣列的大小和乾草堆陣列的大小是多少。根據這些尺寸,如果性能很重要,答案可能完全不同。 –