【发布时间】:2017-01-21 11:16:54
【问题描述】:
PHP 中是否有任何方法可以拥有一个数组并按照与某个字符串最相似的方式对其进行排序。
例如:
$array = array("Bob", "Brad", "Britney");
$userinput = "Bradley123";
/*
function that changes the array to be
array("Brad","Britney","Bob")
from the most similar from the $userinput
*/
【问题讨论】:
-
我认为没有办法做到这一点。
-
你是如何定义“最相似”的?
-
如果你指的是谷歌之类的东西,那么你应该使用数据库并通过它进行搜索,而不是使用数组。
-
没有内置的方法可以做到这一点。您必须自己编写代码。您可能可以将链接到的
similar_text函数 u_mulder 与usort结合使用。