daveboyle99
asked on
php array want to loop through for similar values
I am trying to merge two tables of similar data, but am having the problem that the indexes are text, and dont match in both tables. For example "This Weeks Advertisements" might be "This weeks Advertisement" in the other.
So far I have put all the values from both tables into an array and am comparing them by eye but its taking a long time.
My question is, is there an easy way to search through an array for similar values and group them based on some kind of score that indicates how similar they are?
So far I have put all the values from both tables into an array and am comparing them by eye but its taking a long time.
My question is, is there an easy way to search through an array for similar values and group them based on some kind of score that indicates how similar they are?
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
foreach ($total_names as $r) {
foreach ($total_names as $s) {
$lev = levenshtein($r, $s);
if (($lev<2) && ($lev!=0)) {
echo "$r (Input) <br>$s (Word) $lev (Score)<br><br>\n";
}
}
n.b set_time_limit(0); doesnt always work, use metabase explorer to set CGI_TIMEOUT :)