PHP:找到常见的重复字符串?

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

Take a look at how an autocomplete's functionality works, this is similar to your approach.

I'm sure there's plenty of source codes for autocomplete on google

For the string value of every key in your array:

  1. Throw away all non-alpha characters, i.e. leave only letters such that ctype_alpha($remaining_text) should return true.
  2. Keep an array with the found words as keys, and their frequencies as values, as such:

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

    Only nicer ;)

  3. Sort the array in reverse by using arsort($array);
  4. $array now contains the most found words as its first elements.
  1. you would have to create every possible suffix of every string you have.
  2. create a map for every suffix you found
  3. count the occurence of every suffix in your string array

you can modify the performance with f.ex. limiting the suffix length