$a[] = "paris";
$a[] = "london";
$a[] = "paris";
$a[] = "london tour";
$a[] = "london tours";
$a[] = "london";
$a[] = "londonn";
foreach($a as $name) {
echo $name;
echo '<br>';
}
Output:
paris
london
paris
london tour
london tours
london
londonn
I can eliminate the same words with array_unique
foreach(array_unique($a) as $name) {
echo $name;
echo '<br>';
}
Output:
paris
london
london tour
london tours
londonn
I want to take this further and eliminate similar words. Like, if there is a "london", I want to eliminate "londonn".
So the output will be:
paris
london
london tour
I tried similar_text($name, $name, $percent) but it did not help.
Here is what I tried with my limited of knowledge:
foreach(array_unique($a) as $name) {
$test = $a;
foreach($test as $test1) {
similar_text($name, $test1, $percent);
if ($percent > 90) {
echo $name;
echo '<br>';
}
}
}
Output:
paris
paris
london
london
london
london tour
london tour
london tours
london tours
londonn
londonn
londonn
The source of the words is a search list:
$a[] = "$popular_search";