【发布时间】:2023-03-23 00:57:01
【问题描述】:
有没有比使用 strpos() 循环更好的方法?
我不是在寻找部分匹配,而不是 in_array() 类型的方法。
示例针和干草堆以及期望的回报:
$needles[0] = 'naan bread';
$needles[1] = 'cheesestrings';
$needles[2] = 'risotto';
$needles[3] = 'cake';
$haystack[0] = 'bread';
$haystack[1] = 'wine';
$haystack[2] = 'soup';
$haystack[3] = 'cheese';
//desired output - but what's the best method of getting this array?
$matches[0] = 'bread';
$matches[1] = 'cheese';
即:
magic_function($haystack, %$needles%) !
【问题讨论】:
-
不,不会将
bread与naan bread进行比较。 OP 似乎正在寻找通配符匹配功能。 -
这适用于非精确匹配吗?
-
Dohh - 错过了
naan。比他应该用空格分隔符来分解所有元素,但那根本就不是原生函数。
标签: php