title: Search for same substrings inside php array of strings
body: <p>I have a generated array of strings for example:</p>
  
  <pre><code>$array = [
    0 =&gt; 'Uk.London',
    1 =&gt; 'Uk.Manchester',
    2 =&gt; 'Uk.Liverpool',
    3 =&gt; 'Uk.Cardiff',
  ]
  </code></pre>
  
  <p>or for example:</p>
  
  <pre><code>$array = [
    0 =&gt; "[Text]/ab",
    1 =&gt; "[Text]/cd",
    2 =&gt; "[Text]/ef",
    3 =&gt; "[Text]/gh",
    4 =&gt; "[Text]/il",
  ]
  </code></pre>
  
  <p>I would like to search inside this array if there are similar substrings.
  So in the first case should return <code>Uk.</code> and in the second case should return <code>[Text]/</code>.</p>
  
  <p>Can someone help me please.
  Thanks in advance.</p>
  
  <hr>
  
  <p><strong>1. Edit</strong></p>
  
  <p>Here there is my code:</p>
  
  <pre><code>$array = [
    0 =&gt; 'Uk.London',
    1 =&gt; 'Uk.Manchester',
    2 =&gt; 'Uk.Liverpool',
    3 =&gt; 'Uk.Cardiff',
  ];
  
  $words = Array();
  
  foreach($array as $str)
  $words = array_merge($words, explode(" ", $str));
  
  $index = Array();
  
  
  foreach($words as $word)
          (isset($index[$word]))? $index[$word]++ : $index[$word] = 1;
  
  arsort($index);
  
  return(key($index));
  </code></pre>
  
  <p>But is returning in this case <code>Uk.London</code></p>
  
  <hr>
  
  <p><strong>2. Idea</strong></p>
  
  <p>I was thinking about converting the array in string and then searching for duplicate substrings but I will get something like this:</p>
  
  <p><code>$words = 'Uk.London Uk.Manchester Uk.Liverpool Uk.Cardiff'</code></p>
  
  <p>And I can find the <code>Uk.</code> but I can't check if every item has the same substring.</p>