I örnekte, bir bileşik kelimeleri olduğu bir kelime listesi
- Palanca
- Platon
- PlatonPalanca
I need to remove "Platon" ve "Palanca" ve let only "PlatonPalanca". Used array_unique to remove duplicates, but those composed words vardır tricky...
Should I sort the list by word length ve compvardır one by one? A regular expression is the answer?
güncelleme: kelimelerin listesi ilgili sözler değil sadece, çok daha büyük ve karışık
2 güncelleme: Ben güvenli bir dizeye dizi implode olabilir.
3 güncelleme: Ben bu bir balon tür sanki bunu önlemek için çalışıyorum. Bunu yapmanın daha etkili bir yolu olmalı
Well, I think that a buble-sort like approach is the only possible one :-( I don't like it, but it's what i have... Any better approach?
function sortByLengthDesc($a,$b){
return strlen($a)-strlen($b);
}
usort($words,'sortByLengthDesc');
$count = count($words);
for($i=0;$i<=$count;$i++) {
for($j=$i+1;$j<$count;$j++) {
if(strstr($words[$j], $words[$i]) ){
$delete[]=$i;
}
}
}
foreach($delete as $i) {
unset($words[$i]);
}
update 5: Sorry all. I'm A moron. Jonathan Swift make me realize I was asking the wrong question. Given x words which START the same, I need to remove the shortests ones.
- "Hot, köpek, stve, hotdogstve" ", dog stve, hotdogstve" olması gerektiğini
- "Araba, hayvan, halı" "hayvan, halı" haline gelmelidir
- "Palanca, Platon, PlatonPalanca" should become "Palanca, PlatonPalanca"
- "Platonother, other" should be untouchedm they both start different