foreach
ループを使用します(for
ループでも問題ありません)。試す:
Levenstien for <b><?php echo $_POST["source"]; ?></b> and <b><?php echo $_POST["target"]; ?></b>:
<?php
$string5 = $_POST["source"];
$string6 = $_POST["target"];
$array6 = explode(', ',$string6);
foreach ($array6 as $derp)
{
echo $string5, "/", $derp, ": ", levenshtein($string5, $derp), "<br>";
}
?>
スコア順に出力するには、次を使用します。
Levenstien for <b><?php echo $_POST["source"]; ?></b> and <b><?php echo $_POST["target"]; ?></b>:
<?php
$string5 = $_POST["source"];
$string6 = $_POST["target"];
$array6 = array_map('trim', explode(',',$string6));
$doop = array();
foreach ($array6 as $derp)
{
doop[$derp] = levenshtein($string5, $derp);
}
arsort($doop); // sorts highest element first
foreach ($words as $key => $value)
{
echo sprintf('%s / %s: %s<br />', $string5, $key, $value);
}
?>