PHP: find a common duplicate string?

I have this situation in PHP. I have an array that has these keys, for example, wires-1, wires-2, wires-3. Do I need a function or a way for my program to read these keys and find that the common word is wires? How will this be done in PHP? Thank you for your help.

+3
source share
3 answers

See how the autocomplete function works, it looks like your approach.

I'm sure there are a lot of autocomplete source codes in google

0
source

For the string value of each key in your array:

  • Discard all characters other than alpha, that is, leave only letters so that it ctype_alpha($remaining_text)should return true.
  • :

    $array = new array();
    function found_word($word)
    {  global $array;
       if(!isset($array[$word])) { $array[$word] = 1; }
       else { $array[$word]++; }
    }
    

    ;)

  • arsort($array);
  • $array .
0
  • , .
  • create a map for each suffix you find
  • counts the presence of each suffix in your string array

you can change performance with f.ex. suffix length limit

0
source

All Articles