PHP similar_text选择最高值

时间:2015-05-06 10:40:28

标签: php

我在while循环中使用了like_text:

while ($row = mysql_fetch_array($result)) {
$similiar_name = $row["f_name"];
similar_text($prototype_name, $similiar_name, $percent);
}

我如何回应最高的百分比?

1 个答案:

答案 0 :(得分:2)

将计算结果存储在数组中,然后对该数组进行排序并提取最高结果

$similarities = [];
while ($row = mysql_fetch_array($result)) {
    $similiar_name = $row["f_name"];
    similar_text($prototype_name, $similiar_name, $percent);
    $similarities[$similiar_name] = $percent;
}

rsort($similarities);
echo $similarities[0];