Link to home
Create AccountLog in
Avatar of daveboyle99
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?
SOLUTION
Avatar of MasonWolf
MasonWolf
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of daveboyle99
daveboyle99

ASKER

Thanks for the great answers guys. I solved with the folowing (rather clumsy yet effective) code :

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 :)