我在while循环中使用了like_text:
while ($row = mysql_fetch_array($result)) {
$similiar_name = $row["f_name"];
similar_text($prototype_name, $similiar_name, $percent);
}
如何以最高$百分比回显$ similiar_name?
答案 0 :(得分:1)
将计算结果存储在数组中,然后对该数组进行排序并提取最高结果
$similarities = [];
while ($row = mysql_fetch_array($result)) {
$similiar_name = $row["f_name"];
similar_text($prototype_name, $similiar_name, $percent);
$similarities[$similiar_name] = $percent;
}
arsort($similarities);
echo array_keys($similarities)[0];
或者如果您没有支持阵列解除引用的最新版本的PHP,请替换
echo array_keys($similarities)[0];
与
$words = array_keys($similarities)
echo $words[0];