【发布时间】:2016-04-01 15:33:57
【问题描述】:
$keywords = array('red', 'blue', 'yellow', 'green', 'orange', 'white');
$strings = array(
'She had a pink dress',
'I have a white chocolate',
'I have a green balloon',
'I have a chocolate shirt',
'He had a new yellow book',
'We have many blue boxes',
'I have a magenta tie');
实际上,strings 数组非常庞大(超过 50k 个条目)。
仅运行搜索和提取匹配字符串的最佳方法是什么?
【问题讨论】:
-
如果数据来自数据库,您应该已经在那里过滤。否则你可以使用
array_filter() -
@Shafizadeh 反过来,需要检查每个字符串中是否存在任何关键字。
-
在每个字符串中,你的意思是?否则你的小例子已经没有结果了。
-
@GolezTrol 如果字符串包含 keywords 数组中的任何单词,则条件为真。
-
@jeroen 我现在正在研究array_filter。 :)
标签: php arrays string-matching