PHP:找到常见的重复字符串?
我在PHP中也遇到过这种情况。我有一个包含这些键的数组,例如,wires-1、wires-2、wires-3。我需要一个函数或方法让我的程序读取这些键,并发现常见的单词是电线?在 PHP 中如何实现这一点?感谢您的帮助。
I have this situation in PHP. I have an array that has these keys for example, wires-1, wires-2, wires-3. I need a function or way for my program to read these keys, and find that the common word is wires? How would that be accomplished in PHP? Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看一下自动完成功能的工作原理,这与您的方法类似。
我确信谷歌上有很多自动完成的源代码
Take a look at how an autocomplete's functionality works, this is similar to your approach.
I'm sure there's plenty of source codes for autocomplete on google
对于数组中每个键的字符串值:
ctype_alpha($remaining_text)
应返回true
。保留一个数组,其中找到的单词作为键,其频率作为值,如下所示:
只有更好;)
arsort($array);
反转数组$array
现在包含最常找到的单词作为其第一个元素。For the string value of every key in your array:
ctype_alpha($remaining_text)
should returntrue
.Keep an array with the found words as keys, and their frequencies as values, as such:
Only nicer ;)
arsort($array);
$array
now contains the most found words as its first elements.您可以使用 f.ex 修改性能。限制后缀长度
you can modify the performance with f.ex. limiting the suffix length