在PHP中,有没有像stristr功能,但对于数组? [英] In PHP, is there a function like stristr, but for arrays?
问题描述
基本上,我有一个字符串数组来搜索。如果是只有一个字符串, stristr
将很好地工作。但是,由于它是一个数组,我能想到的唯一一件事就是只运行一个foreach循环和 stristr
字符串每次迭代。
Basically, I have an array of strings to search for. If it were only one string, stristr
would work perfectly. However, since it's an array, the only thing I can think of is to just run a foreach loop and stristr
the string from each iteration.
肯定有更好的方式来做到这一点,我只是不知道这一点。有人可以帮助我在这里?
SURELY there's a better way to do this, I just don't know it. Can anyone help me out here?
修改
举例来说,假设我有这样的数组:
For example, say I have this array:
$阵列=阵列(字符串1,富,酒吧,嘟·喔普);
和此字符串:
$字符串=AW宕人让去那吧;
我要弄清楚,如果 $字符串
包含数组字符串中的一个。
I need to figure out if $string
contains one of the strings from the array.
推荐答案
那么你将不得不通过数组的foreach,因为stristr功能点的返回值。
Well you will have to foreach through the array, as the point of the stristr function is the return value.
这篇关于在PHP中,有没有像stristr功能,但对于数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!